Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set custom theme in Android List Preference

In my Android app, I am using various custom themes in different activities, all of which work fine. All these themes use the same custom styles for buttons, edit controls etc.

My preferences use standard Preference activities, which I define in XML and style via the manifest.

However, when I have a preference that causes an alert dialog to get launched, for example a ListPreference, the dialog uses the standard buttons. It does seem to use my custom EditText style in the EditTextPreference... but not my background or text colour.

Anyone have any idea why this is happening ?

Some of the code:

Styles:

<style name="Theme.Prefs" parent="@android:style/Theme.Holo.Light">
        <item name="android:windowBackground">@drawable/background</item>
    <item name="android:buttonStyle">@style/CustomButtonStyle</item>
        <item name="android:editTextStyle">@style/CustomEditTextStyle</item>
</style>


<style name="CustomButtonStyle" parent="@android:style/Widget.Holo.Button">
    <item name="android:background">@drawable/custom_button</item>
    <item name="android:textSize">@dimen/dialog_text_size_normal</item>
    <item name="android:textColor">@color/dialog_control_colour</item>
</style>


<style name="CustomEditTextStyle" parent="@android:style/Widget.Holo.EditText">
    <item name="android:background">@drawable/custom_textfield</item>
    <item name="android:textColor">@color/dialog_control_colour</item>
    <item name="android:textSize">@dimen/dialog_text_size_normal</item>
</style>

And in the manifest:

<activity
    android:name="com.breadbun.prefs.MainPreferencesActivity"
    android:theme="@style/Theme.Prefs"
    android:screenOrientation="portrait">
</activity>
like image 645
OriginalBigBri Avatar asked Nov 13 '22 05:11

OriginalBigBri


1 Answers

To customize the alertDialog you need to add the second row to your main theme, and then customize the DialogStyle the way you want it.

<style name="AppTheme" parent="android:Theme.Material">
    <item name="android:alertDialogTheme">@style/DialogStyle</item>
</style>
<style name="DialogStyle" parent="android:Theme.Material.Dialog.Alert">
</style>
like image 114
user5214546 Avatar answered Nov 14 '22 22:11

user5214546