Search code examples
androidxmlandroid-actionbar-compat

How to set actionbar height using appcompat library?


How can I change the actionbar's height? I don't know why this isn't working. This is what have I done:

res/values/styles.xml

<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.
        -->

        <item name="actionBarStyle">@style/ActionBarStyle</item>
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

I have created another styles.xml file, so this way I can use the android's namespace.

res/values-v11/styles.xml

<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
    <item name="android:actionBarStyle">@style/ActionBarStyle</item>
</style>

And the actionbar's style file:

res/values/my_custom_style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="ActionBarStyle" parent="@style/Widget.AppCompat.ActionBar">
        <item name="android:height">80dp</item>
        <item name="height">80dp</item>
    </style>
</resources>

The manifest file:

<application
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme" >
<activity
            android:name=".MainActivity"
            android:screenOrientation="portrait" />
</application>

This isn't working, the height didn't change. I have tested on Android 4.4.2.


Solution

  • Set actionBarStyle also on res/values-v11/styles.xml. This is necessary for compatibility support

    res/values-v11/styles.xml

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="actionBarStyle">@style/ActionBarStyle</item>
        <item name="android:actionBarStyle">@style/ActionBarStyle</item>
    </style>