How can I force my Widgets to use a dark theme? - android

In my application, I used Theme.Holo.Light to make the ActionBar look light and I am pretty pleased with the result.
The only problem is that all my widgets (EditText, Spinner, etc..) are acting like the background was white, while I set it a dark blue:
Is there an easy way in the style.xml file where I can force everything to act like the theme was dark?
I know that I could theme the text color, background resources, etc.. But this would be a huge work.
Thank a lot for any hint that could help me to achieve that easily.
Edit: what sounds the best solution, but not working:
<style name="AppBaseTheme" parent="#android:Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
</style>

To solve this (the easy way) you should use Theme.Holo. And Change the actionbar to Theme.Holo.Light.
extend theme:
<style name="MyTheme.Dark" parent="android:Theme.Holo.Light.ActionBar"></style>
use getActionBar().getThemedContext() as the context for inflating your views.

You can use Holoeverywhere library to achieve your result.
HoloEveryWhere

Related

Material Design custom view theme

I am trying to have a default theme with a button. When I do this the button no longer ripples. I believe I need to set a proper parent on the btn_normal style but I can not find the appropiate theme.
btn_normal style works fine if I just apply it via a style to the button directly.
I have tried tons of parents and none of them have worked. Let me know if you have ran into this. Thanks.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:buttonStyle">#style/btn_normal</item>
</style>
<style name="btn_normal">
</style>
You should use RippleDrawable third party library. By that, you can give Ripple effect for Android 7+ version.

Android add custom attribute to styles

I'm trying to implement a feature to let the user change the theme.
I've done this but depending on if the theme is light or dark, I need to use the opposite color to draw line on a canvas. I thought the best way to do this would be to simply call R.style.colorAttribute to get the correct color when doing the drawing.
In the styles.xml I have defined the following themes:
<style name="DarkTheme" parent="android:Theme.Holo" />
<style name="LightTheme" parent="android:Theme.Holo.Light" />
Can anyone help on the best way to add an attribute here which will store the color. I've not done this before and was n't sure if I should use the color.xml file or the styles.xml file.
Thanks
And just to make it clear
I for the dark theme I need a white color
and for the light them I need the same attribute but in black.
If you like a theme, but want to tweak it, just add the theme as the parent of your custom theme. For example, you can modify the traditional light theme to use your own color like this:
<color name="custom_theme_color">#b0b0ff</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">#color/custom_theme_color</item>
<item name="android:colorBackground">#color/custom_theme_color</item>
</style>
More about styles on developer.android.com.

android dialog style properties

I want to change color of the blue parts in the following image:
I know how to use custom styles, I just need to know what are called the properties of these blue parts (I mean something like <item name="android:background">#FF0000</item> ) thx
What I really want to achieve is demonstrated here:
You may inherit the theme used from Android code and change particulars within that.
http://developer.android.com/guide/topics/ui/themes.html
<style name="GreenText" parent="#android:style/TextAppearance">
<item name="android:textColor">#00FF00</item>
</style>
parent holds the value of the default theme. In your case it will be the Dialog theme for Holo.

Light.DarkActionBar menu item text colour unchangeable?

The application I've been developing uses ActionBarSherlock, and the main theme inherits from Theme.Sherlock.Light.DarkActionBar. The design requires that the overflow menu popups have a dark coloured background and white text. This works fine for devices without a physical menu button, and the text appears white as intended. However, if the device DOES have a physical menu button, the text shown in the menu displayed remains black.
My main theme contains
<item name="android:panelBackground">#drawable/menu_hardkey_panel</item>
...Where #drawable/menu_hardkey_panel is a dark coloured 9patch.
The resulting appearance of the menu popup is...
I'm unable to determine why this is happening, or how to manually change the colour of the text. In my main theme, I've tried all of the following...
<item name="android:actionMenuTextColor">#android:color/white</item>
<item name="android:textAppearanceLargePopupMenu">#style/MyMenuTextAppearance.Large</item>
<item name="android:textAppearanceSmallPopupMenu">#style/MyMenuTextAppearance.Small</item>
I've even tried
<item name="android:actionBarWidgetTheme">#style/Theme.MyApp.Dark</item>
...Where Theme.MyApp.Dark is...
<style name="Theme.MyApp.Dark" parent="#style/Theme.Sherlock">
<item name="android:dropDownListViewStyle">#style/DropDownListView</item>
<item name="dropDownListViewStyle">#style/DropDownListView</item>
</style>
None have let me change the text to white. If I make my base theme inherit from Theme.Sherlock, the problem is solved and the text is white, but unfortunately that's not an option.
Not entirely sure about this, but I believe the pop-up menu uses the same styling as the overflow menu. In which case you'd just do something like this.
<item name="android:itemTextAppearance">#style/your_new_text_appearance</item>
<style name="your_new_text_appearance">
<item name="android:textColor">#android:color/white</item>
</style>
Giving it a chance: there is a text appearance called actionMenuTextAppearance. Have you tried that?
Update: I did some more digging and I believe that this file is the layout And there they refer to textAppearanceListItemSmall and textAppearanceSmall. However, it takes this value from a special theme which is specified as following in Theme.Holo.Light
<item name="panelMenuListTheme">#android:style/Theme.Holo.Light.CompactMenu</item>
And like this in Theme.Holo:
<item name="panelMenuListTheme">#android:style/Theme.Holo.CompactMenu</item>
The problems comes from the fact that the parent of Sherlock.__Theme.DarkActionBar is Theme.Sherlock.Light. This is not valid for the dark action bar. Taking the line from Theme.Holo should do the trick.
In my research I haven't found a way to change the text color, but you can at least handle hardkey menus gracefully.
This link provided me with a passable solution to the problem:
https://github.com/jgilfelt/android-actionbarstylegenerator/issues/30
Commenting out the "android:panelBackground" item from my generated theme allowed the text to at least be visible on hardkey menus, even if it doesn't perfectly match the theme.
You could also try replacing the "menu_hardkey_panel_whatever.9.png" drawable with something that will work for your theme and the black text.
For me this solves the problem, try this instead:
<style name="MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
...
<item name="actionBarWidgetTheme">#null</item>
<item name="android:actionBarWidgetTheme">#null</item>
...
</style>
I found the solution, use:
getSupportActionBarContext()
e.g.
ArrayAdapter<CharSequence> list =
ArrayAdapter.createFromResource(getSupportActionBarContext(), R.array.navigation, layout.simple_spinner_item);
list.setDropDownViewResource(layout.simple_spinner_dropdown_item);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setListNavigationCallbacks(list, this);
I think that due to the fact that Theme.Sherlock.Light.DarkActionBar don't style its contents right is due to the actionWidgetTheme attribute is used with a ContextThemeWrapper for inflating the action bar views (Jake Wharton's own words), thus something like the following (not tested) will be needed to fulfill your needs, though breaking your need of not using Theme.Sherlock as parent in one way:
<style name="MyColorTheme" parent="Theme.Sherlock">
<item name="android:actionMenuTextColor">#android:color/white</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
<style name="YourMainTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:actionMenuTextAppearance">#style/MyColorTheme</item>
<item name="actionMenuTextAppearance">#style/MyColorTheme</item>
</style>
Might work or not work. That's the question :)

Holo Dark TabWidget style for Holo Light Theme

I've got a custom theme that inherits from Theme.Holo.Light.DarkActionBar and I'm trying to change the theme's tabWidget style so it to look like if the theme was Theme.Holo Dark.
I've tried this in my theme with no result
<style name="AppTheme" parent="android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:tabWidgetStyle">#android:style/Widget.Holo.TabWidget</item>
...
</style>
The only thing I can appreciate is there is a small change in the blue bar of the tab.
Any idea how to get it? Thanks!
Try also the items "android:tabStripLeft" and "android:tabStripRight".

Categories

Resources