2

I used the following code but the ActionBar title and back button are by default black in color but i need to make them white. Is that possible?

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar1);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setTitle("Account");**strong text**
Juan Cruz Soler
  • 8,172
  • 5
  • 41
  • 44
  • Toolbar 101: http://android-developers.blogspot.cz/2014/10/appcompat-v21-material-design-for-pre.html chapter Toolbar Widget, paragraph DarkActionBar – Eugen Pechanec Jun 22 '16 at 18:32

3 Answers3

3

Add these lines

getSupportActionBar().getThemedContext();
toolbar.setTitleTextColor(0xFFFFFFFF);

Or you can change it to your layout

<android.support.v7.widget.Toolbar
    android:theme="@style/MyTheme.AppBarOverlay"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways"/>

And to your style

<style name="MyTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
Laurence Pardz
  • 292
  • 3
  • 8
0

Try following :

Add this line,

getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.ic_back));

Use back image which is white in color.

To set title color, use toolbar.setTitleTextColor(getResources().getColor(R.color.white));

Ashwini
  • 245
  • 1
  • 7
0

In my case i created new TextView and added it pragmatically to toolbar.

ToolBar toolbar = (Toolbar) findViewById(R.id.app_baar);


TextView text = new TextView(this);
text.setText("Name of your APP");
text.setTextColor(getResources().getColor(R.color.white));


int ORIENTATION_PORTRAIT =1;
if(this.getResources().getConfiguration().orientation==ORIENTATION_PORTRAIT)
{
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
llp.setMargins(0, 10, 0, 0); // llp.setMargins(left, top, right, bottom);
text.setLayoutParams(llp);
}

text.setGravity(Gravity.CENTER_VERTICAL);
toolbar.addView(text);
Ebin Joy
  • 2,690
  • 5
  • 26
  • 39