I need help with styling my custom preference according to the app style(sheet).
I've created a custom preference that shows two settings side-by-side (first name and last name). All is fine, I can edit them using a custom dialog etc, but I am having trouble styling it to look like the other list preferences.
Image below shows what I am trying to do.
I'd like to make the top preference (my custom one) look like the bottom one (straight from settings.xml). As you can see the padding, text color, size etc are all difference; this is possibly because "my" preference uses Linear Layouts + Text Views and not a standard preference list view item.
My custom preference XML came from this answer Android: Creating custom preference
This is my app theme
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
and this is the code for my preference:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:id="@android:id/widget_frame"
android:orientation="horizontal">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@android:id/widget_frame"
android:orientation="vertical">
<TextView
android:id="@+id/firstname"
style="@android:style/TextAppearance.DeviceDefault.SearchResult.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setting_firstname" />
<TextView
android:id="@+id/firstname_data"
style="@android:style/TextAppearance.DeviceDefault.SearchResult.Subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="moo" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@android:id/widget_frame"
android:orientation="vertical">
<TextView
android:id="@+id/lastname"
style="@android:style/TextAppearance.DeviceDefault.SearchResult.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setting_lastname" />
<TextView
android:id="@+id/lastname_data"
style="@android:style/TextAppearance.DeviceDefault.SearchResult.Subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Moo" />
</LinearLayout>
</LinearLayout>
I have two questions basically:
- What is / where can I find the XML that creates a preference list item - is it is standard list view item or its own custom XML?
- How do I make my preference look like a standard one?
I tried to assign android:id="@android:id/widget_frame" to the linear layout (as suggested in the Stackoverflow answer above)
Also tried various style= on the Text views (style="@android:style/TextAppearance.DeviceDefault.SearchResult.Subtitle") but I don't know if this is correct and what other options are available
Other info
My fullname preference is just standard code :
public class FullnamePreference extends DialogPreference {
My settings.xml contains this:
<com.example.Settings.FullnamePreference
android:key="fullname"/>
<Preference
android:key="version"
android:summary="@string/setting_version_summary"
android:title="@string/setting_version" />