2016-06-22 4 views
0

Ich habe den folgenden Code verwendet, aber der ActionBar-Titel und die Zurück-Schaltfläche sind standardmäßig schwarz, aber ich muss sie weiß machen. Ist das möglich?getSupportActionBar Titelfarbe

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar1); 
setSupportActionBar(toolbar); 
getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
getSupportActionBar().setHomeButtonEnabled(true); 
getSupportActionBar().setTitle("Account");**strong text** 
+0

Toolbar 101: http://android-developers.blogspot.cz/2014/10/appcompat-v21-material-design-for-pre.html Kapitel Toolbar Widget Absatz DarkActionBar –

Antwort

0

Versuchen folgende:

diese Zeile hinzufügen,

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

Verwenden Bild zurück, das in der Farbe weiß ist.

Zur Titelfarbe festgelegt, kann toolbar.setTitleTextColor(getResources().getColor(R.color.white));

1

Fügen Sie diese Zeilen

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

Oder Sie es

<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"/> 

Und zu Ihrem Stil

<style name="MyTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 
0
zum Layout ändern verwenden

In meinem Fall habe ich einen neuen TextView erstellt und pragmatisch zur Symbolleiste hinzugefügt.

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