2014-12-07 44 views
0

如何更改操作栏的高度?我不知道为什么这不起作用。这是我做了什么:如何使用appcompat库设置操作栏高度?

RES /价值/ 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> 

我创造了另一种styles.xml文件,所以这样我就可以使用Android的命名空间。

RES /值-V11/styles.xml

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

而且动作条的样式文件:

RES /价值/ 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> 

清单文件:

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

这不是工作,高度没有改变。我已经测试了Android 4.4.2。

回答

1

设置actionBarStyle也在res/values-v11/styles.xml。这是必要的兼容性支持

RES /值-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> 
相关问题