I am trying to figure out the best way to pick best themes for new and old Android versions, e.g. by reading this Trying to use holo theme in Android not working where they define Holo in values-11 and Black in values
Black
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyTheme" parent="#android:style/Theme.Black" />
</resources>
Holo
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyTheme" parent="#android:style/Theme.Holo" />
</resources>
Question 1)
Will that work no matter what minSdkVersion setting I use? I guess that Android for never versions will assume values-11 is better match than values.fallback when no specific folder matches
Question 2)
Assuming above (which I think is the case), how/where do I best define my MyTheme extensions. Suppose I have:
<style name="MyTheme2" parent="MyTheme">
<item name="android:windowTitleSize">44dip</item>
<item name="android:windowTitleBackgroundStyle">#style/MyWindowTitleBackground</item>
</style>
<style name="MyWindowTitleBackground">
<item name="android:background">#android:color/transparent</item>
<item name="android:padding">0px</item>
</style>
Do I have to duplicate that in both values styles.xml files? Or can I somehow place that in a shared folder? From my understand, I don't think that is possible?
I am new to Android, so I am just trying to figure out what would be the best thing to do :)
Independent customization should be created in values/styles. Follow this template: (ANDROID DEFAULT)
In values/styles
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="#android:style/Theme.Black">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
In values-v11/styles
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="#android:style/Theme.Light.NoTitleBar">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
Related
I'm quite new to android. I created an application for api7 to api19 using support library and Theme.AppCompat.Light theme and I'm trying now to apply a custom theme to it but I get the error android:editTextBackground requires API level 11 (current min is 7) on the second line of themes_wvtheme.xml. I would like to know the correct edittext attribute for api<11.
This is my style.xml:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
This is my custom theme themes_wvtheme.xml:
<?xml version="1.0" encoding="utf-8"?>
<item name="android:editTextBackground">#drawable/wvtheme_edit_text_holo_light</item>
<item name="android:listChoiceIndicatorMultiple">#drawable/wvtheme_btn_check_holo_light</item>
<item name="android:listChoiceIndicatorSingle">#drawable/wvtheme_btn_radio_holo_light</item>
<item name="android:buttonStyle">#style/ButtonWVTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonWVTheme</item>
<item name="android:listChoiceBackgroundIndicator">#drawable/wvtheme_list_selector_holo_light</item>
<item name="android:activatedBackgroundIndicator">#drawable/wvtheme_activated_background_holo_light</item>
You can create a style for your EditTexts, and specify a background attribute for it. That is, in style.xml put something like:
<style name="Theme.MyApp.EditText" parent="#android:style/Widget.EditText">
<item name="android:background">#drawable/wvtheme_edit_text_holo_light</item>
<!-- ..other attributes.. -->
</style>
Then, in your app theme, add the line:
<item name="android:editTextStyle">#style/Theme.MyApp.EditText</item>
The oldest API level I've built for using this approach is 8, but it should work for API level 7 as well.
I'm a beginner in android development. And I'm following the training on developer.android.com. But I'm having problem changing actionbar background color right now.
I have the error
Description Resource Path Location Type
error: Error: No resource found that matches the given name (at 'android:background' with value '#colors/orange'). styles.xml /ActionBarColor/res/values line 17 Android AAPT Problem
when I'm refering to res/values/colors.xml from my res/values/styles.xml
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name ="orange">#FF8800</color>
</resources>
styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<item name="actionBarStyle">#style/myActionBar</item>
</style>
<style name = "myActionBar" parent = "Widget.AppCompat.Light.Base.ActionBar.Solid.Inverse">
<item name ="android:background">#colors/orange</item> <!--Error Here-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
I read almost every thread on this but found no clue. My code looks exactly same as the others, as far as I can tell. Please help me. The project target is API19, min ver is API11
added themes.xml as the website says, error stays
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#colors/orange</item>
<!-- Support library compatibility -->
<item name="background">#colors/orange</item>
</style>
</resources>
As I can see, you're using the AppCompat library on your Android project, so you should only use AppCompat resources for theming. Right from the Android training pages on how to Style the Action Bar, in the section "Customize the Background":
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_background</item>
</style>
</resources>
Then apply your theme to your entire app or to individual activities:
<application android:theme="#style/CustomActionBarTheme" ... />
Create an style for the Action Bar based on any existent AppCompat themes and define the background item (for appcompat apps) - MyActionBar in the above example.
Create an style that'll be used by your project that applies the previously created Action bar style, and define the actionBarStyle item (for appcompat apps) - CustomActionBarTheme in the above example.
You would really want to read through the Android Training Pages, they're pretty well explained; and you also have the Android API Guides and the Android API Reference Pages just in case.
i have app which was created in android:Theme.Light. i want to change it to Theme.AppCompat.Light.DarkActionBar but i get
no resource found that matches the given name
'theme.appcompat.light.darkactionbar'
I have android-support-v4.jar, when i try add appcompat_v7 i get errors in codes where is something like it R..... Can I add DarkActionBar to this project without problems with codes? Without changes in code?
I have:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
I want:
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
Ensure that your application is properly linked with the Support Library, with resources (see documentation here).
And don't forget #style/:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
This will prevent the no resource error from occurring.
You might be interested in this tutorial too.
If you're doing this in your manifest, do the following to set the theme for the whole app:
<application
...
android:theme="#style/Theme.AppCompat.Light.DarkActionBar"
...>
in your XML for the specific theme, you need #style, so put the following:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
I want to change the color of the text of menu items in the action bar. I' tried to change the theme but nothing works. I'm ussing API 19:
This is my res\values\styles.xml
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="LoginFormContainer">
<item name="android:padding">28dp</item>
</style>
</resources>
Also the project generated styles.xml in res\values-v11\ res\values-v14\
I don't know if I have to change the theme or just set a property or something, any help I will really appreciate. Thank you!
Finally I found a solution to my problem. This is my final code:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 14 theme customizations can go here. -->
<item name="android:textAppearanceLargePopupMenu" >#style/m_textAppearanceLargePopupMenu</item>
<item name="android:textAppearanceSmallPopupMenu" >#style/m_textAppearanceSmallPopupMenu</item>
</style>
<style name="m_textAppearanceLargePopupMenu" parent="#android:style/TextAppearance.Holo.Widget.PopupMenu.Large">
<item name="android:textColor">#009ad2</item>
</style>
<style name="m_textAppearanceSmallPopupMenu" parent="#android:style/TextAppearance.Holo.Widget.PopupMenu.Small">
<item name="android:textColor">#009ad2</item>
</style>
</resources>
It is my res\values-v14\ file code.
I was confused, what I really wanted was to change the text color to the PopupMenu and it worked for me.
Thanks friends for your help!!
Check this Documentation in the section Customize the Text Color. It says the way you have to do it for the different android API levels.
I know the question seems simple, but not anything like chei here before. So there you go:
In my android application using the Support Library with AppCompat v7, added an ActionBar. Everything works perfectly, except that when the application runs on android 2.3, the background of the ActionBar is dark, and when the squeegee android 4.0.2 ActionBar this background turns gray.
Below is how to define my #style
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
how can I solve this?
This will not work for you on min target as 2.3.3 in case your min target is API level 11 you can change the background color
<resources>
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
I would like to add my observation (using min sdk 8, target sdk 19) for the future readers on this issue.
If you want to set just the background color of the action bar across different android versions, its easier to do it in code.
actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable( getResources().getDrawable(R.color.your_desired_color));
This overrides the default background across versions and set your desired color.
Note: I had seen on various post and tried to set the background color as follows:
ColorDrawable colorDrawable = new ColorDrawable();
colorDrawable.setColor(R.color.your_desired_color);
actionBar.setBackgroundDrawable(colorDrawable);
but it did not work, reason unknown to me for the time being.so I successfully tried the code mentioned above.
if you want to set the background color of the action bar (along with other attributes) not in code, you can use style and theme. I had done the styling as follows.
inside res/values/style.xml
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 11 theme customizations can go here. -->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<!-- custom theme for my app -->
<style name="MyAppTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/bgcolor</item>
</style>
</resources>
inside res/values-v11 and res/values-v14
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 11 theme customizations can go here. -->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<!-- custom theme for my app -->
<style name="MyAppTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/bgcolor</item>
</style>
</resources>
Note:
As I had to have similar look for the action bar across android versions, I had copy-pasted the code in res/values-v11 and res/values-v14 from res/values. But to my surprise,I did not get the desired result. Reason? We need to add the "android" namespace before the tags for android v11 and later. So I changed actionBarStyle to android:actionBarStyle and background to android:background. That brought me the desired result.