2016-06-22 75 views
0

我使用了下面的代码,但ActionBar标题和后退按钮默认为黑色,但我需要将它们变成白色。那可能吗?getSupportActionBar标题颜色

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

工具栏101:http://android-developers.blogspot.cz/2014/10/appcompat-v21-material-design-for-pre.html章工具栏小工具,第DarkActionBar –

回答

0

尝试以下操作:

加入这一行,

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

使用回图像这是白色的。

要设置标题颜色,使用toolbar.setTitleTextColor(getResources().getColor(R.color.white));

1

添加这些行

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

或者,你可以把它改成你的布局

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

和你的风格

<style name="MyTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 
0

在我的情况下,我创建了新的TextView并将其实用添加到工具栏中。

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