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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?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
1 2 3 |
public TimePreference(Context context, AttributeSet attrs) { this(context, attrs, 0); } |
con
1 2 3 |
public TimePreference(Context context, AttributeSet attrs) { this(context, attrs, android.R.attr.dialogPreferenceStyle); } |
Now the preference items have the same style:
One reply on “Padding and margin in DialogPreference”
Thanks a lot! Made my day 😉