2

I am having a really hard time with the styling of my Android application, check out the screenshot:

Screenshot

The screenshot is from a Android 4.0.3 emulator, so I expect the new looks.

There are several problems with it:

  1. The black border around the title of the alert dialog
  2. The blue border around the whole alert dialog
  3. The NumberPicker looks like Android 2.0
  4. The buttons should be black and with no space between them and the border of the dialog

My Styles.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.Splash" parent="android:Theme">
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:windowNoTitle">true</item>
  </style>
  <style name="Theme.Recson.BlueBackground" parent="android:Theme">
    <item name="android:background">#ff2390C8</item>
  </style>
  <style name="Theme.Recson.NoActionBar" parent="Theme.Recson.BlueBackground">
    <item name="android:windowNoTitle">true</item>
  </style>
</resources>

The activity that spawns this alert dialog uses Theme.Recson.BlueBackground. Not specifying any theme for the activity makes it look the way I want it to - except for the missing blue background:

So, I guess, the question is: How to fix my theme?

Community
  • 1
  • 1
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • I also notice you're using the `android:windowNoTitle` property. Since you're using the Holo theme now, this will have no effect: Holo doesn't show title bars - it defaults to show the action bar instead. If you want to hide the action bar, you can append `NoActionBar` to your parent theme. – nhaarman Feb 14 '14 at 08:56

1 Answers1

2

Try using parent="android:Theme.Holo".

Of course, this is only available from API level 11 and up, so you will have to create a separate styles.xml file and place it in the values-v11 folder. In the default styles.xml file use your existing configuration, in the v11 file, you can use Theme.Holo.

Have a look at Styles and Themes - Select a theme based on platform version | Android Developers.

nhaarman
  • 98,571
  • 55
  • 246
  • 278
  • This looks like the most logical solution – japk Feb 14 '14 at 08:45
  • It looks better, but still not perfect: http://screencast.com/t/LCX48KVpNd1l Any ideas on these glitches? (wrong button color, black left and right padding on title) – Daniel Hilgarth Feb 14 '14 at 08:47
  • How do you create the dialog? Do you specify a theme for the dialog? – nhaarman Feb 14 '14 at 08:49
  • @NiekHaarman: I new up an AlertDialog and show it inside an event handler of the activity that you can see in the background. I don't specify a theme, so I assume it simply inherits it from the activity in the background, because I am using its context to get the layout inflater which I use in turn to set the view of the alert dialog. – Daniel Hilgarth Feb 14 '14 at 08:51
  • Okay. Can you play around with the `background` properties? Basically, the `background` property changes the background color of *all* views, and `windowBackground` changes only, well, the window background. Perhaps the `background` property is not what you need. If this has no effect, have a look at [this](http://stackoverflow.com/a/18348490/675383) answer, on how to apply a theme to a dialog. – nhaarman Feb 14 '14 at 08:54
  • OK, so I tried using windowBackground and colorBackground in addition to just background. No change. Applying the theme directly to the dialog makes it worse: http://screencast.com/t/vYFiosZd. The second answer would allow to fix the color of the button, but not the strange padding in the title or the blue border around the dialog... Any ideas here? – Daniel Hilgarth Feb 14 '14 at 09:08
  • I'm afraid the AlertDialog class somehow ignores the `windowBackground` attribute. Despite it not ignoring the `background` attribute, I don't think you want to be using this, because of all the side effects. I think the only solution is to extend the `Dialog` class, and create the layout yourself. There is also [this library](https://github.com/inmite/android-styled-dialogs) for creating styled dialogs, altough I don't have any experience with it. – nhaarman Feb 14 '14 at 09:37