This question has been asked before, but carefully studying the answers on previous posts hasn't helped me decipher the problem.
I'm trying to apply custom styles to the items in a spinner control in my Android app, using a custom theme. I can't get the spinner items to respect the custom styles.
Here's what I have in themes.xml:
<resources>
<style name="CustomTheme" parent="android:Theme">
<item name="android:spinnerItemStyle">#style/CustomSpinnerItem</item>
<item name="android:windowTitleSize">25dp</item> <!-- This works -->
</style>
</resources>
And here's my styles.xml:
<resources>
<style name="CustomSpinnerItem" parent="android:Widget.TextView.SpinnerItem">
<item name="android:textAppearance">#style/CustomTextAppearanceSpinnerItem</item>
<item name="android:padding">20dp</item> <!-- This works fine -->
</style>
<style name="CustomTextAppearanceSpinnerItem" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:textColor">#F00</item> <!-- This does NOT work -->
</style>
</resources>
Note the comments about what's working and what isn't. I'm pretty sure the problem is in the CustomTextAppearanceSpinnerItem section, but I'm at a loss as to what's wrong.
Any suggestions?
This works well for me
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MySpinnerItem" parent="#android:Widget.TextView.SpinnerItem">
<item name="android:textAppearance">#style/MySpinnerTextAppearance</item>
</style>
<style name="MySpinnerTextAppearance" parent="#android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:textColor">#FF0000</item>
</style>
</resources>
Related
The title says it all: how can I style my PreferenceFragmentCompat. My v14/style.xml is
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:editTextStyle">#style/Widget.EditText.White</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>
</style>
<style name="Widget.EditText.White" parent="#android:style/Widget.EditText">
<item name="android:textColor">#ffffffff</item>
</style>
</resources>
The base theme has a black background - the preferences screen is then unreadable as I have black text on that black background.
I've tried many things but I cannot change the text colour.
What I've had to do is to set the fragment container background colour to white whilst the settings fragment is active. An ugly hack and not what I want to have to do.
To answer my own question: my v14/style.xml is now
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:editTextStyle">#style/Widget.EditText.White</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>
</style>
<style name="Widget.EditText.White" parent="#android:style/Widget.EditText">
<item name="android:textColor">#ffffffff</item>
</style>
<style name="PreferenceThemeOverlay.v14">
<item name="android:background">#color/settings_background</item>
<item name="android:textColor">#color/settings_text_colour</item>
<item name="android:textColorSecondary">#color/settings_text_colour_secondary</item>
</style>
</resources>
My problem is now to style a ListPreference.
Why is this so hard? If there is any documentation relating to styling preferences, it is well hidden. Grrrrrr!
Take a look at README for github project
Gericop/Android-Support-Preference-V7-Fix
I'm trying to set up my styles to make all buttons a particular color combination, specifically blue with white text. Here's my main styles.xml:
<resources>
<style name="CustomTheme" parent="MaterialDrawerTheme.Light.DarkToolbar">
<!-- various items -->
<item name="android:buttonStyle">#style/ButtonStyle</item>
</style>
<!-- a couple of other styles -->
<style name="ButtonStyle" parent="android:style/Widget.Button">
<item name="android:textSize">19sp</item>
<item name="android:textColor">#color/primaryTextContrast</item>
<item name="android:background">#color/primary</item>
</style>
</resources>
And in the manifest:
<application
android:name=".CustomApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/application_name"
android:theme="#style/CustomTheme">
color/primary is dark blue, and color/primaryTextContrast is white. On Lollipop, the button looks perfect. On a 4.1 device, it's light gray with black text. Every resource I've found for doing this looks exactly like what I'm doing so I don't know what I'm missing here.
I'm having a similar issue with controlling text size in the base style definition as well.
Update: here are the colors.
<resources>
<color name="primary">#3F51B5</color>
<color name="dark">#303F9F</color>
<color name="accent">#FFCA28</color>
<color name="background">#android:color/white</color>
<!-- Color for text displayed on top of the primary or dark color -->
<color name="primaryTextContrast">#android:color/white</color>
<!-- Color for text displayed on the background color (which I think will always be white) -->
<color name="basicText">#color/primary</color>
<!-- Color for text displayed on the accent color -->
<color name="accentText">#303F9F</color>
</resources>
Here's v19/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="FullscreenTheme" parent="MaterialDrawerTheme.Light.DarkToolbar.TranslucentStatus">
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
Here's v21:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="CustomTheme">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">#android:transition/move</item>
<item name="android:windowSharedElementExitTransition">#android:transition/move</item>
</style>
</resources>
I don't think either of these is what's making it work properly on 5.1.
Using AppCompat 22.1.+ (22.2.0 should work too), I defined a Style like this:
<style name="MyApp.Button.Red" parent="Base.Widget.AppCompat.Button">
<item name="colorButtonNormal">#color/primary</item>
<item name="android:colorButtonNormal">#color/primary</item>
<item name="android:textColor">#android:color/white</item>
</style>
and then applied the theme in a button using the native theme attribute from android namespace, as said in this awesome post from Chris Banes.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_button"
android:theme="#style/MyApp.Button.Red" />
I tried adding buttonStyle without the android: prefix and it solved the problem. Yeah, weird.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="buttonStyle">#style/ButtonStyle</item>
<item name="android:buttonStyle">#style/ButtonStyle</item>
</style>
gradle:compile 'com.android.support:appcompat-v7:22.2.0'
For theme to work properly in android lollipop, you need to extend
ActionBarActivityinstead of Activity.
By doing this change,your theme setting should work properly.
This is general for other people that for lower version of android,you should not use android: tag in item-name definition
`
Am trying to change the background color of the contextual action bar.
I did it in the following manner
v21/themes.xml & themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionModeOverlay">true</item>
<item name="actionModeStyle">#style/Widget.ActionMode</item>
<item name="android:actionModeStyle">#style/Widget.ActionMode</item>
</style>
</resources>
styles.xml
<style name="Widget.ActionMode" parent="#style/Widget.AppCompat.ActionMode">
<item name="background">#color/highlight_green</item>
</style>
The background color works fine in pre-lollipop devices. But does not work in lollipop.
Note: Tried adding
<item name="android:actionModeBackground">#color/highlight_green</item>
<item name="actionModeBackground">#color/highlight_green</item>
as well. But did not work.
Had the same problem since last library update, and adding the "actionModeBackground" item in my theme solved it.
Are you sure you are adding it under MyTheme, and not under Widget.ActionMode ?
Try only the next code:
Styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionModeStyle">#style/ActionMode</item>
</style>
<style name="ActionMode" parent="Widget.AppCompat.ActionMode">
<item name="background">#color/color_bar</item>
<item name="backgroundSplit">#color/color_bar</item>
</style>
This is my first project working with Android (Xamarin) and i was trying to style the ActionBar. I succesfully changed the background color, but now the text within it is either gone or the same color as the background. I think the second because i only changed the background. Below is my Styles.xml.
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<style name="hme" parent="android:Theme.Material">
<item name="android:actionBarStyle">#style/hme.ActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/hme.ActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="hme.ActionBar" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#color/primary</item>
<item name="android:titleTextStyle">#style/hme.ActionBar.Text</item>
<!-- Support library compatibility -->
<item name="background">#color/primary</item>
</style>
<style name="hme.ActionBar.Text" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
<style name="hme.Splash" parent="android:Theme">
<item name="android:windowBackground">#drawable/splash</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
And here is a screenshot on Gyazo of how it looks. (Not enough rep to post a picture): http://gyazo.com/161cd58ced1f7a147b29f8ee6aa401af
I checked other fixes on SO on diffent questions but nothing seems to work, can anybody help me?
You can add
<item name="android:textColorPrimary">#android:color/black</item>
into your hme style:
<style name="hme" parent="android:Theme.Material">
<item name="android:actionBarStyle">#style/hme.ActionBar</item>
<item name="android:textColorPrimary">#android:color/black</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/hme.ActionBar</item>
</style>
Check also:
<item name="android:textColor">#android:color/black</item>
<item name="android:textColorSecondary">#android:color/black</item>
may be useful.
I have this theme in values/styles.xml, that I apply to my whole application.
<!-- Base application theme. -->
<style name="AppTheme" parent="#style/_AppTheme">
<!-- a bunch of things... -->
<item name="android:textColorHighlight">#9999cc00</item>
<!-- a bunch of things... -->
</style>
<style name="_AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"/>
Then in values-v9
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="#style/_AppTheme">
<item name="android:textSelectHandleLeft">#drawable/apptheme_text_select_handle_left</item>
<item name="android:textSelectHandleRight">#drawable/apptheme_text_select_handle_right</item>
<item name="android:textSelectHandle">#drawable/apptheme_text_select_handle_middle</item>
</style>
</resources>
And finally in values-v11
<?xml version="1.0" encoding="utf-8"?>
<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="#style/_AppTheme">
<item name="android:dropDownSpinnerStyle">#style/SpinnerAppTheme</item>
<item name="android:listChoiceBackgroundIndicator">#drawable/apptheme_list_selector_holo_light</item>
<item name="android:activatedBackgroundIndicator">#drawable/apptheme_activated_background_holo_light</item>
<item name="android:textColorHighlight">#9999cc00</item>
<item name="android:textSelectHandleLeft">#drawable/apptheme_text_select_handle_left</item>
<item name="android:textSelectHandleRight">#drawable/apptheme_text_select_handle_right</item>
<item name="android:textSelectHandle">#drawable/apptheme_text_select_handle_middle</item>
</style>
</resources>
All of the drawables are in their respective folder.
This has no effect in changing the text select handle in any part of the application.
Is this because of the AppCompat library use maybe?
How do I repair?
Using this link
http://android-holo-colors.com/
The worst part here was to find the "name" for this item and how it is called inside the theme. So I looked through every drawable in the android SDK folder and finally found the drawables named "text_select_handle_middle", "text_select_handle_left" and "text_select_handle_right".
So the solution is simple: Add these drawables with customized design/color to your drawable folder and add them to your theme style definition like:
<style name="MyCustomTheme" parent="#style/MyNotSoCustomTheme">
<item name="android:textSelectHandle">#drawable/text_select_handle_middle</item>
<item name="android:textSelectHandleLeft">#drawable/text_select_handle_left</item>
<item name="android:textSelectHandleRight">#drawable/text_select_handle_right</item>
</style>