1

I am trying to get title Id of Action Bar so as to inflate color.

Trying same as undermentioned ..

   actionBar = getSupportActionBar();
        int titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
        TextView yourTextView = (TextView) findViewById(titleId);
        actionBar.setTitle("Sign in or Create an account");
        yourTextView.setTextColor(getResources().getColor(R.color.taxi_blue));
        actionBar.setBackgroundDrawable(getResources().getDrawable(R.color.white));
        actionBar.setDisplayShowTitleEnabled(true);

This is working great in higher version but when I try same in lower version I am getting NullPointException

I am getting exception at ..

yourTextView.setTextColor(getResources().getColor(R.color.taxi_blue));

I have used back support library for same.

Really stuck on this.

Any hint on this is appreciated.

AndroidHacker
  • 3,596
  • 1
  • 25
  • 45

1 Answers1

2

action_bar_title is not found in "lower versions".

Since you are only changing the textcolor. You could probably be okay using:

ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>Sign in or Create an account</font>"));

Of course, replace #ff0000 with your color defined by R.color.taxi_blue

Sherif elKhatib
  • 45,786
  • 16
  • 89
  • 106