如何在不使用主题的情况下更改标题栏颜色

5
我怎样在不使用主题的情况下改变Android标题栏的背景颜色。感谢。
3个回答

4
尝试使用下面的代码:
View titleView = getWindow().findViewById(android.R.id.titlebar);
    if (titleView != null) {
      ViewParent parent = titleView.getParent();
      if (parent != null && (parent instanceof View)) {
        View parentView = (View)parent;
        parentView.setBackgroundColor(Color.RED);
      }
    }

1
@Friz14 你在哪里找到的?我遇到了类似的问题,但是我找不到android.R.id.titlebar。谢谢 +1。 - ateiob
我正在使用标题而不是标题栏,但我无法更改标题栏的颜色.. 我需要设置其他什么才能使其工作吗? - Vikas Gupta

0

ActionBar bar = getActionBar(); bar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.material_blue_gray1)));

ActionBar bar = getActionBar(); bar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.material_blue_gray1)));


如果你正在使用android.support.v7.app.ActionBar,那么请在getActionBar的位置使用getSupportActionBar()。 - Shubham Jain

-1

他特别要求不带主题 - ateiob

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接