Styling the action bar compatibility - android

I copied this extract directly from the android online documentation Styling the Action Bar
For Android 3.0 and higher only
When supporting Android 3.0 and higher only, you can define the action bar's background like this:
res/values/themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
</style>
</resources>
My minSdk is 11 and yet I'm receiving compatibility warnings at the parent tag. Why?

Theme.Holo.Light.DarkActionBar is only 4.0+, that's why you get the warning. To fix that you can use Holo Light, or change the theme according the the Android version (so you'll have light on Honeycomb and Light with dark actionbar on ICS+).

Related

Android actionbar style ignored by later devices, using appcompat v7

I am using the Action Bar support library (appcompat v7), my app is set to a minimum api of 7, and a target of 21.
I have two styles files, a base one, and one targeted at devices api 11+.
When running the app on a device running KitKat, it seems that android:actionBarStyle is ignored, leaving the action bar styled as default (#style/Widget.AppCompat.ActionBar.Solid), instead of applying the given background.
But if I remove my v11 styles/comment them out, KitKat listens to the actionBarStyle attribute set in the base styles.xml file and sets my custom background without any problems.
So my question, where am I going wrong with the v11 styles?
From what I understand, according to the android docs, you are supposed to supply the additional styles for devices running 11+ using the android: prefix, but this just doesn't seem to be working for me.
Stripped down, this is my /res/values/styles.xml file:
<style name="My.Theme" parent="#style/Theme.AppCompat">
<item name="actionBarStyle">#style/ActionBar.Solid</item>
</style>
<style name="ActionBar.Solid" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="background">#drawable/ab_solid_</item>
</style>
and this is my /res/values-v11/styles.xml file:
<style name="My.Theme" parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle">#style/ActionBar.Solid</item>
</style>
<style name="ActionBar.Solid" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#drawable/ab_solid_</item>
</style>
as you can see, the only difference between the two is the use of the android: prefix.
According to the official doc, with the new AppCompat-v21, you can remove all of values-v14+ Action Bar styles and use only one theme declaration, in values:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Set AppCompat’s actionBarStyle -->
<item name="actionBarStyle">#style/MyActionBarStyle</item>
</style>

Styling Actionbar Appcompat devider

I am working on an app where I have to modify the app Actionbar. I am able to design it according to the requirement, but facing problem in designing the white line beneath the action bar. Well, I have got some hack where I can take the view and design it. But I want it to style it using style.xml.
EDIT
Now google has released toolbar that you can modify easily.
You can style your action bar like the below code -
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
</style>
and also please check the link - https://developer.android.com/training/basics/actionbar/styling.html to get more information. Hope it helped you.

Android ActionBar background colors.xml not working

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.

android:windowActionBarOverlay & android:actionBarStyle requires api level 11

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.

Android: ActionBar Hidden

I have an old app which now when run on tablets like the Xoom, hides the ActionBar. The app was written before the ActionBar existed so some old code is hiding the actionbar.
What in an old app can hide the ActionBar? I need to change it so that the ActionBar and therefore the menu can be shown:
Here's my very simple Theme:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme.Black">
<item name="android:windowNoTitle">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">#android:color/transparent</item>
</style>
<style name="TextViewStyled" parent="#android:style/Widget.TextView">
<item name="android:textStyle">normal</item>
<item name="android:lineSpacingMultiplier">1.22</item>
</style>
</resources>
And here's the only window settings I use:
getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_RIGHT_ICON);
Using android:Theme.Black as your theme parent is what's "hiding" the action bar. The Holo and DeviceDefault theme families include an action bar by default, but the legacy theme family (from which Theme.Black derives) does not.
Use a theme declared with the same name "MyTheme" in res/values-v11/themes.xml with a parent of #android:style/Theme.Holo. This version of the theme will be used on devices running API level 11 (Android 3.0, where Holo and the action bar were introduced) or newer. You should similarly use Widget.Holo.TextView instead of Widget.TextView when declaring a custom view style to work within the Holo theme.

Categories

Resources