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.
Simply put
actionBarSize
item under MyTheme style, like this: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 setheight
:S.D.'s solution does not work for me. I used AppCompat v-21 library in my case. And I just add
to my layout file and it works.
Add this to the custom theme style XML that you are referencing from your manifest file:
For instance if your manifest file looks something like this:
Your theme style should be -at least- like this:
Use
height
attribute,actionBarSize
if for something else.Explanantion:
From source code of ActionBar:
We can see that
R.styleable.ActionBar_height
is being used for height.Stylable
property names are generated ascomponent_attribute
(If you have ever used a customstylable
view, you'd have notice this). Hence,Actionbar
is the name of component andheight
is the name of the attribute to use. Since this is a system attribute, hence defined underandroid
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
:This style can now be set as app theme by using
android:theme="@style/AppTheme"
in<application>
tag of theAndroidManifest.xml
.Note the use of duplicate entries
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 exampleapp:showAsAction="always"
in menu xml files.Update Apr 2015
AppCompat Library v22 is also available. Read through the article to know what's new.
Make sure to add S.D.'s code to styles.xml and then add
to the
<application>
element in the main manifest. (I'm a noob and it took me about 2 hours to find that out.)