简体   繁体   English

如何在暂停应用程序时更改操作栏的标题文本颜色?

[英]How can I change the title text color of the action bar when the app is paused?

How can I change the title text color of the action bar when the app is paused? 如何在暂停应用程序时更改操作栏的标题文本颜色? As you can see below, these two apps have two different colors for its text; 如下所示,这两个应用程序的文本有两种不同的颜色; black, and white. 黑和白。

Edit: There's very little going on in my onPause() function. 编辑:我的onPause()函数很少发生。 Can the title be modified programmatically from here? 可以从这里以编程方式修改标题吗?

@Override
protected void onPause() {
  Log.d(TAG, "onPause");
  super.onPause();
}

在此输入图像描述

 @Override
    protected void onPause() {
        Log.d(TAG, "onPause");
        super.onPause();
        getSupportActionBar().setTitleColor(Color.RED);
    }

or you could do this: 或者你可以这样做:

  @Override
    protected void onPause() {
        Log.d(TAG, "onPause");
        super.onPause();
        int actionBarTitleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
        if (actionBarTitleId > 0) {
            TextView title = (TextView) findViewById(actionBarTitleId);
            if (title != null) {
                title.setTextColor(Color.RED);
            }
        }
    }

More info here: 更多信息:

http://developer.android.com/reference/android/app/Activity.html#setTitleColor(int) http://developer.android.com/reference/android/app/Activity.html#setTitleColor(int)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM