Customize themes not working - android

i have to customize my whole application theme and i am trying to implement my custom theme.
i am able to implement custom theme but it is showing error when i apply it in manifest file.
here is my code for custome theme:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
</style>
</resources>

You should provide more details about the error you are getting. At first sight I can see you are using Theme.Holo.Light.DarkActionBar, which I believe is only available for Android 4.x, so if you are targeting a previous version of Android you could get an error.
Try adding a style.xml file to each of the following folders:
res/values
res/values-v11
res/values-v14
Replace the referenced theme with Theme.Light in the style.xml file of the first folder. Use Theme.Holo.Light for v11 and leave Theme.Holo.Light.DarkActionBar in the style.xml file under v14.
Also bear in mind you cannot style the action bar under versions prior to Honeycomb (v11). Check the documentation for the ActionBar to get more details, in particular the information related to the AppCompat library.
I hope that helps. Otherwise, please provide more information about the error you are getting.

Change to
<?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>
In manifest apply theme as
android:theme="#style/CustomActionBarTheme" >
Your min sdk in manifest should be 14. Use appcompact from the support library if you wish to support actionbar below api level 11.
Also check this
http://developer.android.com/guide/topics/ui/actionbar.html
https://developer.android.com/training/basics/actionbar/styling.html

<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
<item name="android:windowNoTitle">false</item>
<item name="android:windowBackground">#color/transparent</item>
</style>
<style name="CustomWindowTitleBackground">
<item name="android:background">#drawable/button_black</item>
</style>
put this code in style.xml and just change theme attribute of application tag in AndroidManifest.xml like
<application android:icon="#drawable/ic_launcher"
android:theme="#style/CustomTheme">
.
Thats it.

Related

Action Bar android change height [duplicate]

I would like to change the action bar size. I have tried the following coding.
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/CustomActionBar</item>
</style>
<style name="CustomActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<!-- <item name="android:background">#drawable/action_bar_style</item> -->
<item name="android:actionBarSize">15dp</item>
<item name="android:background">#drawable/header_bar</item>
</style>
But the action bar size didn't change. Is there another way? I am using api level 11.
Thanks.
Use height attribute, actionBarSize if for something else.
<item name="android:height">#dimen/bar_height</item>
Explanantion:
From source code of ActionBar:
mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
We can see that R.styleable.ActionBar_height is being used for height. Stylable property names are generated as component_attribute (If you have ever used a custom stylable view, you'd have notice this). Hence, Actionbar is the name of component and height is the name of the attribute to use. Since this is a system attribute, hence defined under android namespace.
Update Dec-2014:
AppCompat library is now provided to extend support for latest ActionBar (or Toolbar) and theme support to old android versions. Below is an example of such an application theme /res/values/styles.xml:
<resources>
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<!-- native widgets will now be "tinted" with accent color -->
<item name="colorAccent">#color/accent</item>
<!--Action bar style-->
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="Widget.AppCompat.Light.ActionBar">
<item name="android:titleTextStyle">#style/AppTheme.ActionBar.TitleText</item>
<item name="titleTextStyle">#style/AppTheme.ActionBar.TitleText</item>
<item name="android:height">#dimen/bar_height</item>
<item name="height">#dimen/bar_height</item>
</style>
<style name="AppTheme.ActionBar.TitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textSize">#dimen/bar_text_size</item>
<item name="android:textColor">#color/bar_text_color</item>
</style>
</resources>
This style can now be set as app theme by using android:theme="#style/AppTheme" in <application> tag of the AndroidManifest.xml.
Note the use of duplicate entries
<item name="android:actionBarStyle">
<item name="actionBarStyle">
The ones without android namespace are there for supporting both compatibility library and native attributes.Some of these attributes didn't exist under android namespace on older versions and belong to support library.
In some other places, you'll need to use app namespace (xmlns:app="http://schemas.android.com/apk/res-auto"), for example app:showAsAction="always" in menu xml files.
Update Apr 2015
AppCompat Library v22 is also available. Read through the article to know what's new.
Simply put actionBarSize item under MyTheme style, like this:
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarSize">15dp</item>
<item name="actionBarSize">15dp</item>
...
</style>
Explanation:
In R.styleable we see that R.styleable.Theme_actionBarSize is a styleable attribute defined at Theme level.
Also, from source code res/values/styles.xml we see how actionBarSize is used to set height:
<style name="Widget.ActionBar">
...
<item name="android:height">?android:attr/actionBarSize</item>
Add this to the custom theme style XML that you are referencing from your manifest file:
<item name="android:windowTitleSize">58dip</item>
For instance if your manifest file looks something like this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
**android:theme="#style/AppTheme"** >
Your theme style should be -at least- like this:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowTitleSize">54dip</item>
</style>
S.D.'s solution does not work for me.
I used AppCompat v-21 library in my case.
And I just add
android:layout_height="#dimen/actionBarSize"
android:minHeight="#dimen/actionBarSize"
to my layout file and it works.
Make sure to add S.D.'s code to styles.xml and then add
android:theme="#style/thin_ab"
to the <application> element in the main manifest. (I'm a noob and it took me about 2 hours to find that out.)

change background colour on Android ActionBar

I have been trying to change the background colour of my ActionBar in my app. But it seems to give me some error.
<?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>
The error I get is on the
<item name="background">#drawable/actionbar_background</item>
I just want to change the background of the actionBar to a different colour.
Help will be appreciated. Thanks
If you target for minimum API level 11 , you can change ActionBar's background color by defining custom style, as:
<resources>
<style name="MyTheme" 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>
And, set "MyTheme" as theme for application / activity.
You can also use this online tool to generate a full customized ActionBar
Here is tool
It's also possible to change the color of the ActionBar programmatically, just call this line:
getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.my_color)));
That's also possible via getSupportActionBar() (if you're using ActionBarSherlock).

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.

Applying a theme to v7 Support Action Bar

I am using the support v7 library to implement ActionBar in my app..I have this in my styles.xml file
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBarTheme</item>
</style>
<style name="ActionBarTheme" parent="android:Widget.ActionBar">
<item name="android:background">#FFFF0000</item>
</style>
</resources>
However, Eclipse complains in the actionBarStyle line. The error is this one:
android:actionBarStyle requires API level 11 (current min is 8)
What can I do to apply my theme to API levels 8-10?
You need to provide two API specific styles.xml. In your values/styles.xml use
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/ActionBarTheme</item>
</style>
and in your values-v14/styles.xml use
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBarTheme</item>
</style>
If you use latest v7 support library (v21 at the time of this post), there is no need to add android: prefix to any action bar attributes anymore.
In your case, adding the following to values/styles.xml will be sufficient:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/ActionBarTheme</item>
</style>
Reference: https://chris.banes.me/2014/10/17/appcompat-v21/#migration-from-previous-setup

How to change action bar size

I would like to change the action bar size. I have tried the following coding.
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/CustomActionBar</item>
</style>
<style name="CustomActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<!-- <item name="android:background">#drawable/action_bar_style</item> -->
<item name="android:actionBarSize">15dp</item>
<item name="android:background">#drawable/header_bar</item>
</style>
But the action bar size didn't change. Is there another way? I am using api level 11.
Thanks.
Use height attribute, actionBarSize if for something else.
<item name="android:height">#dimen/bar_height</item>
Explanantion:
From source code of ActionBar:
mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
We can see that R.styleable.ActionBar_height is being used for height. Stylable property names are generated as component_attribute (If you have ever used a custom stylable view, you'd have notice this). Hence, Actionbar is the name of component and height is the name of the attribute to use. Since this is a system attribute, hence defined under android namespace.
Update Dec-2014:
AppCompat library is now provided to extend support for latest ActionBar (or Toolbar) and theme support to old android versions. Below is an example of such an application theme /res/values/styles.xml:
<resources>
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<!-- native widgets will now be "tinted" with accent color -->
<item name="colorAccent">#color/accent</item>
<!--Action bar style-->
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="Widget.AppCompat.Light.ActionBar">
<item name="android:titleTextStyle">#style/AppTheme.ActionBar.TitleText</item>
<item name="titleTextStyle">#style/AppTheme.ActionBar.TitleText</item>
<item name="android:height">#dimen/bar_height</item>
<item name="height">#dimen/bar_height</item>
</style>
<style name="AppTheme.ActionBar.TitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textSize">#dimen/bar_text_size</item>
<item name="android:textColor">#color/bar_text_color</item>
</style>
</resources>
This style can now be set as app theme by using android:theme="#style/AppTheme" in <application> tag of the AndroidManifest.xml.
Note the use of duplicate entries
<item name="android:actionBarStyle">
<item name="actionBarStyle">
The ones without android namespace are there for supporting both compatibility library and native attributes.Some of these attributes didn't exist under android namespace on older versions and belong to support library.
In some other places, you'll need to use app namespace (xmlns:app="http://schemas.android.com/apk/res-auto"), for example app:showAsAction="always" in menu xml files.
Update Apr 2015
AppCompat Library v22 is also available. Read through the article to know what's new.
Simply put actionBarSize item under MyTheme style, like this:
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarSize">15dp</item>
<item name="actionBarSize">15dp</item>
...
</style>
Explanation:
In R.styleable we see that R.styleable.Theme_actionBarSize is a styleable attribute defined at Theme level.
Also, from source code res/values/styles.xml we see how actionBarSize is used to set height:
<style name="Widget.ActionBar">
...
<item name="android:height">?android:attr/actionBarSize</item>
Add this to the custom theme style XML that you are referencing from your manifest file:
<item name="android:windowTitleSize">58dip</item>
For instance if your manifest file looks something like this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
**android:theme="#style/AppTheme"** >
Your theme style should be -at least- like this:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowTitleSize">54dip</item>
</style>
S.D.'s solution does not work for me.
I used AppCompat v-21 library in my case.
And I just add
android:layout_height="#dimen/actionBarSize"
android:minHeight="#dimen/actionBarSize"
to my layout file and it works.
Make sure to add S.D.'s code to styles.xml and then add
android:theme="#style/thin_ab"
to the <application> element in the main manifest. (I'm a noob and it took me about 2 hours to find that out.)

Categories

Resources