I implemented a Time Picker in the preference using the code found here where the class TimePreference extends the class DialogPreference but I found a lack of alignment with the other preference items because of a different setting of the margins and/or padding.
For example the following xml file:
<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <CheckBoxPreference android:defaultValue="false" android:key="download_preference" android:summaryOff="off" android:summaryOn="on" android:title="Schedule forecast download" /> <eu.lucazanini.arpav.meteo.preference.TimePreference android:defaultValue="08:30" android:dependency="download_preference" android:dialogLayout="@layout/time_picker_preference" android:key="download_time_pref" android:summary="08:30" android:title="Download time" /> </PreferenceScreen>
which contains a CheckBoxPreference and a TimePreference and it has the following screenshot:
where the style for the TimePreference is different from that one for the CheckBoxPreference.
I solved the problem by replacing the constructor
public TimePreference(Context context, AttributeSet attrs) { this(context, attrs, 0); }
con
public TimePreference(Context context, AttributeSet attrs) { this(context, attrs, android.R.attr.dialogPreferenceStyle); }
Now the preference items have the same style:
Leave a Reply