gpt4 book ai didi

android - 操作栏背景未更改

转载 作者:太空宇宙 更新时间:2023-11-03 11:27:57 24 4
gpt4 key购买 nike

我尝试使用以下代码更改操作栏的背景。它适用于 4.3 但不低于 4.3。使用以下代码,将设置空背景,即。旧背景已删除,但未设置新背景。请帮助我。

    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));

}

}
}

最佳答案

最后,我找到了解决方案。这是通过设置背景后显示和隐藏操作栏的标题来实现的。

getActionBar().setBackgroundDrawable(ContextCompat.getDrawable(this,R.drawable.inbox_header)); 
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);

谢谢大家的关心。

关于android - 操作栏背景未更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18223839/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com