安卓3.0:不能风格的动作栏的操作项按钮 [英] Android 3.0: cannot style Action Bar 's action item buttons

查看:111
本文介绍了安卓3.0:不能风格的动作栏的操作项按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是开发引导与主体的http://开发商.android.com /引导/主题/ UI / actionbar.html#ActionItems

Here is the dev guide related to the subject http://developer.android.com/guide/topics/ui/actionbar.html#ActionItems

因此​​,我们必须在活动

So we have in activity

public class MyActivity extends Activity {

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    super.onCreateOptionsMenu(menu);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.my_menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    switch (item.getItemId())
    {
    case R.id.first_menu_button:
        return true;
    case R.id.second_menu_button:
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

其中R.menu.my_menu为

Where R.menu.my_menu is

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/first_menu_button"
        android:showAsAction="always"
        android:icon="@drawable/btn_first"/>
    <item
        android:id="@+id/second_menu_button"
        android:showAsAction="always"
        android:icon="@drawable/btn_second"/>
</menu>

要的风格,按键 http://developer.android.com/导/主题/ UI / actionbar.html#ActionItemStyles 说,我们应该采用Android:actionButtonStyle属性。我做这样的:

To style that buttons http://developer.android.com/guide/topics/ui/actionbar.html#ActionItemStyles say we should use android:actionButtonStyle attribute. I've done it like this:

在清单:

<activity android:name="com.root.test.MyActivity"
    android:theme="@style/CustomActionBarStyle"
</activity>

在styles.xml:

In styles.xml:

<style name="CustomActionBarStyle" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionButtonStyle">@style/customActionButtonStyle</item>
    <item name="android:windowActionBar">true</item>
    <item name="android:windowNoTitle">false</item>   
</style>

<style name="customActionButtonStyle" parent="@android:style/Widget.Holo.Light.ActionButton">
    <item name="android:[...]
</style>

问题是,不管我写 customActionButtonStyle ,它只是忽略它。在 CustomActionBarStyle 和其他atributes(更加复杂,他们JAST省略为简单起见)。我的主要purpuse是设置自定义填充。是否有任何其他方式做到这一点,像一些其他的,不是安卓actionButtonStyle 属性?或者有些人知道如何得到这个工作? (机器人:abItemPadding属性只加3.1)

Problem is that whatever I write in customActionButtonStyle, it's just ignoring it. Other atributes in CustomActionBarStyle works (even more complicated, they are jast omit for the sake of simplicity). My main purpuse was to set custom padding. Is there any other way to do that, like some other, not android:actionButtonStyle attribute? Or some one knows how to get this work? (android:abItemPadding attribute added only in 3.1)

感谢。

推荐答案

大多数风格的元素会工作,但填充被用于生成操作按钮的系统布局提供,可能不会对你有什么期望。大多数操作栏指标,如填充和利润一般应单独留UX的一致性。即使该项目的填充属性您注意,就是要对信息​​的应用程序,可能要使用它的风格自己的自定义操作的看法。

Most style elements will work but padding is supplied by the system layouts used to generate the action buttons and likely will not do what you expect. Most action bar metrics such as padding and margins should generally be left alone for UX consistency. Even the item padding attribute you noted is meant to be informational for apps that may want to use it to style their own custom action views.

这篇关于安卓3.0:不能风格的动作栏的操作项按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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