Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: DialogPreference color/style?

Tags:

android

My main preference activity is set to "@android:style/Theme.Light". One of my preferences is a DialogPreference who's Dialog contains a ListView. The ListView's dialog is dark grey (because DialogPreference uses AlertBuilder which creates dark grey dialogs) and the text in the list is black (because Theme.Light causes listViews to have black text). Is there an easy way to either get the ListView to behave with the same style as the dark dialog? Or to get the dark dialog to behave with the same style as the light activity?

EDIT:

Based on Merlin's comments, it seems like what I should try to do is create a LightDialog Theme. In order to do this I tried: 1. extending android's Theme.Light and adding the dialogy properties from Theme.Dialog

<style name="Theme.LightDialog" parent="@android:style/Theme.Light">
  <item name="android:windowFrame">@null</item> 
  <item name="android:windowTitleStyle">@android:style/DialogWindowTitle</item> 
  <item name="android:windowBackground">@android:drawable/panel_background</item> 
  <item name="android:windowIsFloating">true</item> 
  <item name="android:windowContentOverlay">@null</item> 
  <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> 
</style>

... and 2. extending android's Theme.Dialog and adding the lighty properties from Theme.Light.

   <style name="Theme.LightDialog" parent="@android:style/Theme.Dialog">
          <item name="android:windowBackground">@drawable/screen_background_light</item> 
          <item name="android:colorBackground">@android:color/background_light</item> 
          <item name="android:colorForeground">@androidcolor/bright_foreground_light</item> 
          <item name="android:colorForegroundInverse">@android:color/bright_foreground_light_inverse</item> 
          <item name="android:textColorPrimary">@android:color/primary_text_light</item> 
          <item name="android:textColorSecondary">@android:color/secondary_text_light</item> 
          <item name="android:textColorTertiary">@android:color/tertiary_text_light</item> 
          <item name="android:textColorPrimaryInverse">@android:color/primary_text_dark</item> 
          <item name="android:textColorSecondaryInverse">@android:color/secondary_text_dark</item> 
          <item name="android:textColorTertiaryInverse">@android:color/tertiary_text_dark</item> 
          <item name="android:textColorPrimaryDisableOnly">@android:color/primary_text_light_disable_only</item> 
          <item name="android:textColorPrimaryInverseDisableOnly">@android:color/primary_text_dark_disable_only</item> 
          <item name="android:textColorPrimaryNoDisable">@android:color/primary_text_light_nodisable</item> 
          <item name="android:textColorSecondaryNoDisable">@android:color/secondary_text_light_nodisable</item> 
          <item name="android:textColorPrimaryInverseNoDisable">@android:color/primary_text_dark_nodisable</item> 
          <item name="android:textColorSecondaryInverseNoDisable">@android:color/secondary_text_dark_nodisable</item> 
          <item name="android:textColorHint">@android:color/hint_foreground_light</item> 
          <item name="android:textColorHintInverse">@android:color/hint_foreground_dark</item> 
    </style> 

Both of these attempts failed because they use non-public attributes. Any suggestions on how to create a LightDialog theme?

like image 606
ab11 Avatar asked Apr 15 '11 19:04

ab11


2 Answers

You can inherit defult themes when creating styles in Android.

Please read the documentation on Applying Styles and Themes specifically the section on inheritance

You should be able to take Theme.light and correct any issues that you have with it.

You may find that different vendors alter the themes on their devices so if you are targeting a broad range of hardware then you may be better creating a full theme to ensure that your app is consistent on all platforms.

UPDATE

As stated in this answer Consistent UI color in all Android devices there are public and non-public attributes. The answer provides a link to a list of public attributes however kernel.org is still down so you will need to dig through the source for core/res/res/values/public.xml

like image 160
Moog Avatar answered Sep 20 '22 20:09

Moog


You can specify style of DialogPreference's dialog using android:alertDialogTheme (supported starting from API 11) them property of preferences activity:

<style name="PreferencesActivityTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">        
    <item name="android:alertDialogTheme">@style/Theme.MyDialog</item>
</style>

<style name="Theme.MyDialog" parent="@style/Theme.AppCompat.Light.Dialog">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
like image 32
GregoryK Avatar answered Sep 20 '22 20:09

GregoryK