如何更改操作栏大小 [英] 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>
但是操作栏的大小没有改变.还有其他方法吗?我正在使用 API 级别 11.
But the action bar size didn't change. Is there another way? I am using api level 11.
谢谢.
推荐答案
使用 height
属性,actionBarSize
用于其他用途.
Use height
attribute, actionBarSize
if for something else.
<item name="android:height">@dimen/bar_height</item>
说明:
来自ActionBar的源代码:
From source code of ActionBar:
mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
我们可以看到 R.styleable.ActionBar_height
被用于高度.Stylable
属性名称生成为 component_attribute
(如果您曾经使用过自定义的 stylable
视图,您就会注意到这一点).因此,Actionbar
是组件的名称,height
是要使用的属性的名称.由于这是一个系统属性,因此定义在 android
命名空间下.
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.
2014 年 12 月更新:
AppCompat 库现在提供扩展对最新 ActionBar(或工具栏)的支持和对旧 android 版本的主题支持.以下是此类应用程序主题的示例 /res/values/styles.xml
:
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>
现在可以通过在 AndroidManifest 的
.<application>
标签中使用 android:theme="@style/AppTheme"
将此样式设置为应用主题.xml
This style can now be set as app theme by using android:theme="@style/AppTheme"
in <application>
tag of the AndroidManifest.xml
.
注意重复条目的使用
<item name="android:actionBarStyle">
<item name="actionBarStyle">
没有android
命名空间的那些是为了支持兼容性库和原生属性.其中一些属性在旧版本的android命名空间下不存在,属于支持库.
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.
在其他一些地方,您需要使用 app
命名空间 (xmlns:app="http://schemas.android.com/apk/res-auto"
),例如在菜单 xml 文件中的 app:showAsAction="always"
.
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.
2015 年 4 月更新
AppCompat Library v22 也可用.通读文章以了解新内容.
AppCompat Library v22 is also available. Read through the article to know what's new.
这篇关于如何更改操作栏大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!