I am making an android app and using android-support-v7-appcompat to make sure my app support action bars from android version 2.2 and up.
I need to make the Action Bar overlay and use a translucent background so I have modified the styles.xml to this code :
<resources>
<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>
<!-- TRANSLUCENT THEME -->
<style name="TranslucentAB" parent="Theme.AppCompat.Light">
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionBarStyle">#style/BlackBar</item>
<item name="actionBarStyle">#style/BlackBar</item>
</style>
<!-- TRANSLLUCENT COLOR STYLE -->
<style name="BlackBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/halfblack</item>
<item name="background">#drawable/halfblack</item>
</style>
</resources>
and modified manifest file to adapt the new ActionBar as :
android:theme="#style/TranslucentAB"
The problem is that the following two lines of code require API level 11 and up :
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionBarStyle">#style/BlackBar</item>
but I need to support from API level 8 and up. If I remove these two lines the app runs fine on Android 2.2 with black translucent action bar. But if I run the app in Android 4.3 the app launches with a solid white action bar. halfblack is just a png file in drawable folder with 70% black color.
Found solution to my problem :
I have to make separate styles.xml in res/values-v11 to support the same functionality in android 3.0 and up
To use the action bar overlay with the support library, do this:
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
Notice how the style name does not include the android: prefix.
Related
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">#color/accent</item>
</style>
</resources>
Please try to resolve the problem.
android:Theme.Material requires API level 21 and so it's cleared that your minSDKVersion is lower than 21.
If you really want to develop app for API 21 then declare android:minSDKVersion=21.
And if in case you want to provide compatibility to lower version then you need to use support library, which is commonly known as AppCompat library.
You can access above attributes using AppCompat:
<item name=”colorPrimary”>#color/primary</item>
<item name=”colorPrimaryDark”>#color/primary_dark</item>
Actually, you can use this attribute, using the support library:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<item name="colorPrimary">...</item>
</style>
You can also use the others:
<item name="colorPrimaryDark">...</item>
<item name="colorAccent">...</item>
android:colorPrimary is supported only from API level 21. You can see the error message in android studio and in eclipse below:
android:colorPrimary requires API level 21 (current min is 14)
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 am working with action bar and i want to customize the action bar logo. For that i have written code (below) but its working for Samsung and MicroMax devices but not for Lenovo K900 and Sony Ericssion Xperia z1. What should i do?
Api 16 its working fine but not in 17 (4.2)
Code:
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:logo">#drawable/product_category_logo</item>
<item name="android:background">#drawable/actionbar_theme</item>
<item name="android:backgroundStacked">#color/black</item>
<item name="android:backgroundSplit">#color/white</item>
<item name="android:textColor">#000000</item>
<item name="android:textSize">16sp</item>
</style>
Values-v14 Folder:
<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="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
Values-v11 Folder:
<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:Theme.Holo.Light"> -->
<style name="AppBaseTheme" parent="android:Theme.Light"><!-- Recent changes -->
<!-- API 11 theme customizations can go here. -->
</style>
Guy i don't know what should i do. Please help me out.
I would suggest you to use ActionBarSherlock project in your application. Because this project already handles this kind of things for you.
And just for the sake of verification, Google is also using this ActionBar in its Google I/O app.
You can also download this project from GitHub ActionBarSherlock which also includes demo versions of this open source project.
To add ActionBarSherlock to your project:
Simply git clone the repo from GitHub in your workspace. And then import it as -> create project from existing source in Eclipse.
After this go to Project->Properties->Android and Add it as Library.
Here is your answer for importing it: Importing Actionbarsherlock into eclipse
And after importing it look for the Sample projects in it, how they are making use of Sherlock Action Bar. You will get a lot of info from there.
Most important thing about ActionBarSherlock is that you can also use it for Android OS below 3.0 but official Android API provide Action Bar widget only above OS v3.0. So you can target your app for all kind of users, those who are using OS above 3.0 and below 3.0, both will be targeted.
Please add below theme in all folder - values,vaules-11values-14
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:logo">#drawable/product_category_logo</item>
<item name="android:background">#drawable/actionbar_theme</item>
<item name="android:backgroundStacked">#color/black</item>
<item name="android:backgroundSplit">#color/white</item>
<item name="android:textColor">#000000</item>
<item name="android:textSize">16sp</item>
</style>
i think you have to use actionbarsharelock or actionbarcompart for < android 3.0
but first put this theme in values-11,values-14 and test the app.
also use theme MyActionBar in android manifest file.
try and let me k'no
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.