是否有可能改变活动的标题栏的颜色而不FEATURE_CUSTOM_TITLE?有可能、而不、标题栏、颜色

2023-09-08 09:44:24 作者:回忆那么疼

到目前为止,我已经找到了改变的活动的标题栏的颜色(即一个通过activity.setTitle()和activity.setProgress())要求一个 FEATURE_CUSTOM_TITLE

All the solutions I have found so far for changing the color of the activity's title bar (i.e. the one accessed via activity.setTitle() and activity.setProgress()) mandate a FEATURE_CUSTOM_TITLE:

http://stackoverflow.com/a/2285722/869501

不过,我已经使用 FEATURE_PROGRESS 和Android不允许对组合与其他标题功能的自定义标题(由AndroidRuntimeException的方式),我不想放弃那该多好进度扎那是我的活动的一个组成部分。

But I am already using FEATURE_PROGRESS and Android forbids combining custom titles with other title features (by way of AndroidRuntimeException) and I don't want to give up that nice progress bar that's an integral part of my activity.

有关更改活动标题栏的颜色而不FEATURE_CUSTOM_TITLE的可能性,唯一的线索是另一个线程SO :

The only hint about a possibility of changing the color of activity's title bar without FEATURE_CUSTOM_TITLE was in another SO thread:

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

但是,如果我尝试使用code作为是, android.R.id.titlebar 解决不了!

我在哪里可以找到 android.R.id.titlebar

我必须将它定义自己? (如果答案是肯定的,不是本在本质上是FEATURE_CUSTOM_TITLE?)

Do I have to define it myself? (if the answer is yes, isn't this in essence a FEATURE_CUSTOM_TITLE?)

推荐答案

简答题(现在,直到一个更好的答案到来):否

Short answer (for now, until a better answer comes along): No.