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>
Related
I am new to android application development.I used http://android-holo-colors.com/
to create theme for my application.
It created a theme named ei_theme.
I got the drawable folders,layout,and values folder.
The values folder consist of colors_ei_theme,dimens_ei_theme,styles_ei_theme,themes_ei_theme.
Now i am confused what to add in the manifest file to use the theme.
I guess u cant add more than one theme to in application tag in the manifest.
Can u please tell me how to use these.
here are the contents of styles_ei_theme
<?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 parent="android:Widget.Holo.AutoCompleteTextView" name="AutoCompleteTextViewEi_Theme">
<item name="android:dropDownSelector">#drawable/ei_theme_list_selector_holo_dark</item>
<item name="android:background">#drawable/ei_theme_edit_text_holo_dark</item>
</style>
-<style parent="android:Widget.Holo.Button" name="ButtonEi_Theme">
<item name="android:background">#drawable/ei_theme_btn_default_holo_dark</item>
</style>
-<style parent="android:Widget.Holo.ImageButton" name="ImageButtonEi_Theme">
<item name="android:background">#drawable/ei_theme_btn_default_holo_dark</item>
</style>
-<style name="TabEi_Theme">
<item name="android:gravity">center_horizontal</item>
<item name="android:paddingLeft">16dip</item>
<item name="android:paddingRight">16dip</item>
<item name="android:background">#drawable/ei_theme_tab_indicator_holo</item>
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">1</item>
<item name="android:minWidth">80dip</item>
</style>
-<style name="TabTextEi_Theme">
<item name="android:textColor">#ffffff</item>
<item name="android:textSize">12sp</item>
<item name="android:textStyle">bold</item>
<!-- v14 <item name="android:textAllCaps">true</item> -->
<item name="android:ellipsize">marquee</item>
<item name="android:maxLines">2</item>
<item name="android:maxWidth">180dip</item>
</style>
</resources>
here are contents of themes_ei_theme
<?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 parent="android:Theme.Holo" name="Ei_Theme">
<item name="android:editTextBackground">#drawable/ei_theme_edit_text_holo_dark</item>
<item name="android:textColorHighlight">#9933b5e5</item>
<item name="android:textSelectHandleLeft">#drawable/ei_theme_text_select_handle_left</item>
<item name="android:textSelectHandleRight">#drawable/ei_theme_text_select_handle_right</item>
<item name="android:textSelectHandle">#drawable/ei_theme_text_select_handle_middle</item>
<item name="android:autoCompleteTextViewStyle">#style/AutoCompleteTextViewEi_Theme</item>
<item name="android:listChoiceIndicatorMultiple">#drawable/ei_theme_btn_check_holo_dark</item>
<item name="android:listChoiceIndicatorSingle">#drawable/ei_theme_btn_radio_holo_dark</item>
<item name="android:buttonStyle">#style/ButtonEi_Theme</item>
<item name="android:imageButtonStyle">#style/ImageButtonEi_Theme</item>
</style>
</resources>
There are two ways to apply theme to your activity through AndroidManifest.xml file.
1- Apply theme in the application tag. This applies this theme to all activities in the application like:
<application
android:theme = "#style/Ei_Theme" >
...
</application>
2- Apply theme to each activity individually in AndroidManifest.xml under application tag. This applies this theme to only this activity:
<application >
<activity
android:theme = "#style/Ei_Theme" >
...
</activity>
</application>
How to set attribute in my app, to change the system UI background when open my app; like the picture?
Place this is your values-v21/styles.xml, only for Android 5.0 and up :
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/color_primary</item>
<item name="colorPrimaryDark">#color/color_secondary</item>
<item name="colorAccent">#color/color_accent</item>
<item name="android:statusBarColor">#color/color_primary</item>
</style>
</resources>
and in your colors.xml file :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="color_primary" type="color">#yourColor</item>
<item name="color_secondary" type="color">#yourColor</item>
<item name="color_accent" type="color">#yourColor</item>
</resources>
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.
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>
My app with tabs has two themes. In each theme tabs have different images in selected and unselected state. How I can properly reference to image by theme?
For example. I have in themes.xml
<?xml version="1.0" encoding="utf-8"?>
<style name="LightTheme" parent="#android:style/Theme.Light">
<item name="tabShows">#drawable/ic_tab_shows_unselected_light</item>
<item name="tabShowsSelected">#drawable/ic_tab_shows_selected_light</item>
<item name="tabNews">#drawable/ic_tab_news_selected_light</item>
<item name="tabNewsSelected">#drawable/ic_tab_news_unselected_light</item>
</style>
<style name="DarkTheme" parent="#android:style/Theme.Black">
<item name="tabShows">#drawable/ic_tab_shows_unselected_dark</item>
<item name="tabShowsSelected">#drawable/ic_tab_shows_selected_dark</item>
<item name="tabNews">#drawable/ic_tab_news_selected_dark</item>
<item name="tabNewsSelected">#drawable/ic_tab_news_unselected_dark</item>
</style>
Also I have a tab_shows.xml and tab_news.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="#drawable/ic_tab_shows_selected_light"/>
<item android:state_selected="false" android:drawable="#drawable/ic_tab_shows_unselected_light" />
How I can reference to needed image in selector according to current theme?
This not work for me
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="?tabShowsSelected"/>
<item android:state_selected="false" android:drawable="?tabShows" />
In layout files this works, I mean reference to style via ?styleName
Build your style A and style B
in your case you put android:drawable="#drawable/ic_tab_shows_selected_light" instead of background (I just copied snipets from my code)
#000
<style name="styleB">
<item name="android:background">#000</item>
</style>
your theme A
<style name="Theme.A">
<item name="pageBackground">#style/styleA</item>
</style>
theme B
<style name="Theme.Blue">
<item name="pageBackground">#style/styleB</item>
</style>
in your attr.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="pageBackground" format="reference" />
</resources>
finally in your widget you do style="?pageBackground"
You can find your answer here
http://www.androidengineer.com/2010/06/using-themes-in-android-applications.html
Edit
(Additional information by Lukap in comments)
Define one or more themes in themes.xml and set the definitions of your styles there.
Define custom attributes, a.k.a. custom styles, in attrs.xml.
Describe what the values of your custom styles are in styles.xml.
But you will need read more about the attrs.xml
<item name="android:background">? android:attr/activatedBackgroundIndicator</item>
</style>
Instead, we are referring to the value of some other attribute – activatedBackgroundIndicator – from our inherited theme. Whatever the theme defines as being the activatedBackgroundIndicator is what our background should be.