title: Where and how can I find the layout files used by Android classes?
body: <h3>Problem</h3>
  
  <p>The Android SDK classes refer to pre-defined layouts using resource IDs.</p>
  
  <p>In my example, I am creating a custom <code>Preference</code> class and want to create a custom layout (including custom widgets) for that preference type. This all works fine, for example I can have a <code>TextView</code> displaying the preference title specified with <code>android:title</code> in XML (which is <em>no</em> custom attribute).</p>
  
  <p>The problem is that I want the style of my custom layout to conform with the style used by the standard Android <code>Preference</code> classes. This includes for example the text size and style. I could simply try it out to find the matching style but I suspect that the style Android uses is general so that it would adapt with the general style of the app.</p>
  
  <h3>Approaches</h3>
  
  <p>I looked into the <code>Preference</code> class in the SDK and found that for the title it does the following:</p>
  
  <pre><code>TextView titleView = (TextView) view.findViewById(com.android.internal.R.id.title)
  </code></pre>
  
  <p>This hints that all the style is defined in a layout file. Now my question is: how to find this layout file? I wonder whether the resource id used here is enough, it looks so general that it might be even used for multiple purposes (that is, titles in other places than the <code>Preference</code> class). Is that the case?</p>
  
  <p>To find the layout file, I looked for example in <code>&lt;android-sdk&gt;/platforms/android-24/data/res/layout</code> and it indeed contains some resources with names including "preference".</p>
  
  <p>For example, the file <code>preference_category.xml</code> looks as follows:</p>
  
  <pre><code>&lt;TextView xmlns:android="http://schemas.android.com/apk/res/android"
      style="?android:attr/listSeparatorTextViewStyle"
      android:id="@+android:id/title"
  /&gt;
  </code></pre>
  
  <p>Here a <code>title</code> id is defined. Is that an id the above <code>com.android.internal.R.id.title</code> would refer to?</p>
  
  <p>I can find further relevant layout files, where <code>preference_child.xml</code> looks quite promising:</p>
  
  <pre><code>&lt;TextView android:id="@+android:id/title"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:singleLine="true"
              android:textAppearance="?android:attr/textAppearanceMedium"
              android:ellipsize="marquee"
              android:fadingEdge="horizontal" /&gt;
  </code></pre>
  
  <p>But still I would have to guess whether it is the file I am looking for. Thus the question is: How do I find the right layout file? There is not much documentation in the XML files. <strong>How does one in general find the layout files used at different places in the Android framework?</strong></p>
  
  <p>A related question (<a href="https://stackoverflow.com/q/20314912/905686">Where can I find default AlertDialog layout xml file? </a>) has an answer indicating that I looked at the right directory in the SDK. However, the answer does not tell how in general one proceeds to find the layout one is looking for.</p>
  
  <h3>The concrete case with a custom <code>Preference</code></h3>
  
  <p>Relevant post: <a href="https://stackoverflow.com/a/24781710/905686">Android: Creating custom preference</a></p>
  
  <p>In the linked answer the author suggests (by the given code) to create an own title <code>TextView</code>. I am wondering whether one can instead reuse the layout given by Android, keeping the <code>TextView</code>s for title and summary and just adding the own widget at the place noted in the XML, with id <code>@android:id/widget_frame</code>. Would that be possible without copying it and adapting it in a new layout file? The full file <code>preference_child.xml</code> from the Android SDK looks as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!-- Copyright (C) 2006 The Android Open Source Project
  
       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at
  
            http://www.apache.org/licenses/LICENSE-2.0
  
       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.
  --&gt;
  
  &lt;!-- Layout for a visually child-like Preference in a PreferenceActivity. --&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:minHeight="?android:attr/listPreferredItemHeight"
      android:gravity="center_vertical"
      android:paddingStart="16dip"
      android:paddingEnd="?android:attr/scrollbarSize"&gt;
  
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:minWidth="@dimen/preference_widget_width"
          android:gravity="center"
          android:orientation="horizontal"&gt;
          &lt;ImageView
              android:id="@+android:id/icon"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center"
              /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;RelativeLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginEnd="6dip"
          android:layout_marginTop="6dip"
          android:layout_marginBottom="6dip"
          android:layout_weight="1"&gt;
  
          &lt;TextView android:id="@+android:id/title"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:singleLine="true"
              android:textAppearance="?android:attr/textAppearanceMedium"
              android:ellipsize="marquee"
              android:fadingEdge="horizontal" /&gt;
  
          &lt;TextView android:id="@+android:id/summary"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_below="@android:id/title"
              android:layout_alignStart="@android:id/title"
              android:textAppearance="?android:attr/textAppearanceSmall"
              android:textColor="?android:attr/textColorSecondary"
              android:maxLines="4" /&gt;
  
      &lt;/RelativeLayout&gt;
  
      &lt;!-- Preference should place its actual preference widget here. --&gt;
      &lt;LinearLayout android:id="@+android:id/widget_frame"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:minWidth="@dimen/preference_widget_width"
          android:gravity="center"
          android:orientation="vertical" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>