<ListPreference android:defaultValue="1" android:dialogTitle="dialogTitle" android:entries="@array/entries" android:entryValues="@array/entryValues" android:key="key" android:title="@string/Title" />
1 answer
<com.your.domain.ThemedListPreference android:defaultValue="1" android:dialogTitle="@string/select_type" android:entries="@array/pref_secur_titles" android:entryValues="@array/pref_secur_values" android:key="key" android:theme="@style/ListPreferenceTheme" android:title="Title" />
Create a new class, for example ThemedListPreference:
import android.content.res.TypedArray; import android.view.ContextThemeWrapper; import android.util.AttributeSet; import android.content.Context; import android.preference.ListPreference; public class ThemedListPreference extends ListPreference { private static int[] ATTRS = { android.R.attr.theme }; private ContextThemeWrapper mContextWrapper; public ThemedListPreference(Context context){ this(context, null); } public ThemedListPreference(Context context, AttributeSet attrs){ super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); mContextWrapper = new ContextThemeWrapper(context, a.getResourceId(0, 0)); a.recycle(); } @Override public Context getContext(){ return mContextWrapper; } }
Add to style.xml:
<style name="ListPreferenceTheme" parent="android:Theme.Material.Light"> <item name="android:colorPrimary">@color/primary</item> <item name="android:colorPrimaryDark">@color/accent</item> <item name="android:colorAccent">@color/accent</item> <item name="android:dialogTheme">@style/DialogStyle</item> <item name="android:alertDialogTheme">@style/DialogStyle</item> </style> <style name="DialogStyle" parent="android:Theme.Material.Light.Dialog"> <item name="android:colorAccent">@color/accent</item> </style>
|
android listpreference style
- Vladyslav Matviienko