我似乎无法弄清楚为什么我无法更改操作栏文本的文本颜色..
我一直在尝试一些风格组合,我似乎并不明白为什么其中一个尚未奏效。
我使用的是自定义字体,并认为它可能与字体有关,但我已经尝试更改本机字体的颜色。下面你可以找到我目前所处的位置,我尝试过多种分层样式,但无济于事。有没有人遇到过这个问题?
以下是我最近尝试更改操作栏文字颜色
<resources>
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/teal_500</item>
<item name="android:actionBarStyle">@style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle"
parent="Widget.AppCompat.ActionBar">
<item name="android:background">@color/teal_500</item>
<item name="android:titleTextStyle">@style/ActionBarTitleColor</item>
</style>
<style name="ActionBarTitleColor" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<!-- Customize your theme here. -->
<item name="android:textColor">@color/teal_50</item>
</style>
</resources>
以下是主要活动
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
configureTitle();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void configureTitle(){
// SpannableString s = new SpannableString("Photoswap");
//s.setSpan(new TypefaceSpan(this, "Pacifico.ttf"), 0, s.length(),
// Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// Update the action bar title with the TypefaceSpan instance
// ActionBar actionBar = getSupportActionBar();
// actionBar.setTitle(s);
}
}
答案 0 :(得分:0)
第1步:获取action_bar_title的ID
int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
第2步:使用TextView
TextView abTitle = (TextView) findViewById(titleId);
abTitle.setTextColor(colorId);