如何更改操作栏的大小 [英] How to change action bar size

查看:124
本文介绍了如何更改操作栏的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变操作栏的大小。我曾尝试下面的编码。

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.

感谢。

推荐答案

使用高度属性, actionBarSize 如果别的东西。

Use height attribute, actionBarSize if for something else.

<item name="android:height">@dimen/bar_height</item>

Explanantion:

从动作条的来源$ C ​​$ C:

From source code of ActionBar:

mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);

我们可以看到, R.styleable.ActionBar_height 被用于高度。 风格化属性名称产生的 component_attribute (如果你曾经使用的自定义风格化视图,你就必须通知本)。因此,动作条是组件的名称和高度是使用属性的名称。由于这是一个系统属性,因此在安卓定义命名空间。

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:

<一个href="http://android-developers.blogspot.in/2014/10/appcompat-v21-material-design-for-$p$p.html">AppCompat库现在提供扩展的最新动作条(或工具条)以及对旧的Andr​​oid版本的主题支持。下面是这样一个应用主题 /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>

用途&gt; &LT主题=@风格/ AppTheme:

这风格现在可以通过使用安卓设置为应用程序的主题code>标签的的Andr​​oidManifest.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">

没有机器人命名空间中的那些在那里为同时支持兼容库和这些属性的本地attributes.Some下的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.

在其他一些地方,你需要使用应用命名空间(的xmlns:程序=htt​​p://schemas.android.com / APK / RES-AUTO),例如应用程序:showAsAction =总是菜单中的XML文件

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月

<一个href="http://android-developers.blogspot.in/2015/04/android-support-library-221.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:%20blogspot/hsDu%20(Android%20Developers%20Blog)">AppCompat库V22 也可以。通读文章,知道什么是新的。

AppCompat Library v22 is also available. Read through the article to know what's new.

这篇关于如何更改操作栏的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆