Is it possible to change the color of activity's title bar without FEATURE_CUSTOM_TITLE?

前提是你 提交于 2019-12-08 19:28:53

问题


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:

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

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.

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

But if I try to use the code as is, android.R.id.titlebar cannot be resolved!

Where do I find that android.R.id.titlebar?

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


回答1:


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




回答2:


Hmm, if there weren't an "android" tacked on to the beginning of that, I would say that no, it's not a FEATURE_CUSTOM_TITLE, as it's not a system title bar. With the "android" in there, I really don't know.

It looks sorta like something I've done before, which is running with android:theme="@android:style/Theme.NoTitleBar" in the manifest and then creating a titlebar like view at the top of each layout.



来源:https://stackoverflow.com/questions/11263829/is-it-possible-to-change-the-color-of-activitys-title-bar-without-feature-custo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!