本文介绍了如何隐藏在动作条按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样做的编辑模式,在平板电脑Gmail应用的风格。如果用户presses在动作条的编辑按钮,比我想告诉他/她的动作看来,这对左侧完成按钮,右侧的删除按钮。

我在这里工作没有actionbarsherlock一个例子: https://开头code。 google.com/p/romannurik-$c$c/source/browse/misc/donediscard

我想坚持到actionbarsherlock,出于兼容性考虑。

这是我在onCreateOptionsMenu解决的方式:

<$p$p><$c$c>getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.white));getSupportActionBar()的setIcon(R.drawable.white)。的for(int i = 0; I&LT; menu.size();我++){    menu.getItem(ⅰ).setVisible(假); }

getSupportActionBar()setDisplayHomeAsUpEnabled(假); 什么也不做,所以我必须设置主页图标白色1x1像素绘制。

我也不得不设置动作条的背景颜色,作为的ActionView的背景颜色。如果我没有,比1x1的家图标将有填充周围,和原来的背景颜色将是围绕着白色的home键可见。

任何人有这个更好的解决办法?

编辑:我也不得不改变风格:

 &LT;样式名称=Theme.Styled父=Theme.Sherlock.Light&GT;
        &LT;项目名称=机器人:homeAsUpIndicator&GT; @可绘制/白&LT; /项目&GT;
        &LT;项目名称=homeAsUpIndicator&GT; @可绘制/白&LT; /项目&GT;
&LT; /风格&GT;
 

Also..settings机器人:homeAsUpIndicator增加,从8我最小API等级11,这也是一个问题。

解决方案

如果您使用的是API 14级或以上,没有使用ActionbarSherlock,这code。在 onCreateOptionsMenu 将禁用向上按钮,取出左侧插入符,并删除的图标:

 动作条动作条= getActionBar();
如果(动作条!= NULL){
    actionBar.setHomeButtonEnabled(假); //禁用按钮
    actionBar.setDisplayHomeAsUpEnabled(假); //取出左侧插入符号
    actionBar.setDisplayShowHomeEnabled(假); //删除图标
}
 

I would like to do an edit mode, in the style of the tablet gmail app.If the user presses the edit button on the actionbar, than I would like to show him/her an action view, that has a done button on the left side, and a delete button on the right.

I have an example that works without actionbarsherlock here:https://code.google.com/p/romannurik-code/source/browse/misc/donediscard

I would like to stick to actionbarsherlock, for compatibility reasons.

This is the way I solved it in onCreateOptionsMenu:

getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.white));
getSupportActionBar().setIcon(R.drawable.white);

for (int i = 0; i < menu.size(); i++) {
    menu.getItem(i).setVisible(false); }

getSupportActionBar().setDisplayHomeAsUpEnabled(false); does nothing, so I had to set the home icon to a white 1x1 pixel drawable.

I also had to set the background color of the actionbar, as the actionview's background color. If I had not, than the 1x1 home icon would have padding around it, and the original background color would be visible around the white home button.

Anyone got a better solution for this?

edit:I also had to change the style:

<style name="Theme.Styled" parent="Theme.Sherlock.Light">
        <item name="android:homeAsUpIndicator">@drawable/white</item>
        <item name="homeAsUpIndicator">@drawable/white</item>
</style>

Also..settings android:homeAsUpIndicator increased my min api level from 8 to 11 which is also an issue.

解决方案

If you're on API level 14 or above and are not using ActionbarSherlock, this code in onCreateOptionsMenu will disable the up button, remove the left caret, and remove the icon:

ActionBar actionBar = getActionBar();
if (actionBar != null) {
    actionBar.setHomeButtonEnabled(false); // disable the button
    actionBar.setDisplayHomeAsUpEnabled(false); // remove the left caret
    actionBar.setDisplayShowHomeEnabled(false); // remove the icon
}

这篇关于如何隐藏在动作条按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 19:59