简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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