Reputation: 68506
I'm writing my first Android application at the moment and I'm trying to maintain consistency. I've already implemented my own style of header for grouping input fields:
Now I've just implemented my PreferenceFragments and they put my header to shame! Is there a way to duplicate these headers automagically created by Android for the preference category titles?
Is this a built in widget, or is it just text styling with a separate View for the bar as I've done in my original header? If it is just styling, how do I achieve an identical look and feel?
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/header_my_tasks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/content_main_heading_my_tasks"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_alignParentRight="true"
android:layout_alignBottom="@id/header_my_tasks"
android:text="Last updated 26/01/2014 15:11:04"/>
<View
android:id="@+id/divider_my_tasks"
android:background="#CCC"
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_weight="0"
android:layout_below="@id/header_my_tasks" />
</RelativeLayout>
Upvotes: 0
Views: 158
Reputation: 20426
The layout file for preference category in called preferences_category_holo.xml
(see Android Source code). It uses style, which is called Widget.TextView.ListSeparator
. Attribute is called listSeparatorTextViewStyle
. I assume, if you apply this style to your TextView
on the left hand side, then you should see same design. HEre is the style declaration from Android's styles.xml
file.
<style name="Widget.TextView.ListSeparator">
<item name="android:background">@android:drawable/dark_header_dither</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">?textColorSecondary</item>
<item name="android:textSize">14sp</item>
<item name="android:gravity">center_vertical</item>
<item name="android:paddingStart">8dip</item>
</style>
Upvotes: 1
Reputation: 68506
I managed to work it out myself in the end. Just apply the following style to a TextView:
style="?android:attr/listSeparatorTextViewStyle"
Upvotes: 1