动作条背景没有被改变 [英] Actionbar background is not being changed

查看:107
本文介绍了动作条背景没有被改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试与下面code要更改动作条的背景。它的工作原理与4.3,但4.3没有下文。用下面的code,空的背景被设置IE浏览器。旧的背景被删除,但新的背景不被设置。 请帮我。

 公共类TestActivity延伸活动{

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        // TODO自动生成方法存根
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.testing);
    }

    / **
     *当点击更改背景按钮回调
     * @参数v
     * /
    公共无效onStartClicked(视图v){
        诠释敏= 0;
        INT最大值= 2;

        0和2之间包容//随机数发生器
        INT POS =敏+(INT)(的Math.random()*((最大值 - 最小值)+ 1));

        如果(POS == 0){
            getActionBar()。setBackgroundDrawable(
                    。getResources()getDrawable(R.drawable.header));
        }否则如果(位置== 1){
            getActionBar()。setBackgroundDrawable(
                    。getResources()getDrawable(R.drawable.inbox_header));

        }否则,如果(POS == 2){
            getActionBar()。setBackgroundDrawable(
                    。getResources()getDrawable(R.drawable.outbox_header));

        }

    }
}
 

解决方案

最后,我找到了解决办法。它是通过来达到的显示和隐藏的操作栏的标题设置背景后。

  getActionBar()。setBackgroundDrawable(
                    。getResources()getDrawable(R.drawable.inbox_header));
actionBar.setDisplayShowTitleEnabled(真正的);
actionBar.setDisplayShowTitleEnabled(假);
 

感谢大家的关注。

I have tried with the following code to change the background of the actionbar. It works with 4.3 but not below 4.3. With the following code, null background is being set ie. old background is removed but new background is not being set. Please help me.

    public class TestActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.testing);
    }

    /**
     * Callback when button is clicked to change background
     * @param v
     */
    public void onStartClicked(View v) {
        int Min = 0;
        int Max = 2;

        //Random number generator between 0 and 2 inclusive
        int pos = Min + (int) (Math.random() * ((Max - Min) + 1));

        if (pos == 0) {
            getActionBar().setBackgroundDrawable(
                    getResources().getDrawable(R.drawable.header));
        } else if (pos == 1) {
            getActionBar().setBackgroundDrawable(
                    getResources().getDrawable(R.drawable.inbox_header));

        } else if (pos == 2) {
            getActionBar().setBackgroundDrawable(
                    getResources().getDrawable(R.drawable.outbox_header));

        }

    }
}

解决方案

Finally,I found the solution. It was acheived by showing and hiding the title of action bar after setting background.

 getActionBar().setBackgroundDrawable(
                    getResources().getDrawable(R.drawable.inbox_header)); 
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);

Thank you all for your concern.

这篇关于动作条背景没有被改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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