设置文本颜色为android设备的sherlokactionbar的标题2.3
问题描述:
我正在使用actionbarsherlok我的android项目的库支持actionbar下面的3.0 devices.I设法改变文字颜色为黑/蓝为特定屏幕的操作栏标题在上面的android 3.0。 对于此实现的,我发现这个这是工作在Android 3.0设置文本颜色为android设备的sherlokactionbar的标题2.3
int titleId = getResources().getIdentifier("action_bar_title", "id",
"android");
TextView titleTv= (TextView) findViewById(titleId);
if(titleTv!= null){
titleTv.setTextColor(getResources().getColor(R.color.blue));
titleTv.setTypeface(Typeface.createFromAsset(getAssets(),
"helvetica_medium.otf"));
}
以上但是,对于具有2.3机器人设备,我正在titleTv = NULL。 有没有解决方法? 在此先感谢。
答
经过大量的搜索终于得到了 我只是说这style.xml
<style name="Actionbar.Music.TitleText" parent="@style/Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">@style/MyApp.SherlockActionBarStyle</item>
<item name="android:actionBarStyle">@style/MyApp.SherlockActionBarStyle</item>
</style>
<style name="MyApp.SherlockActionBarStyle" parent="@style/Widget.Sherlock.ActionBar">
<item name="titleTextStyle">@style/MyApp.ActionBar.TextAppearance</item>
</style>
<style name="MyApp.ActionBar.TextAppearance" parent="@style/TextAppearance.Sherlock.Widget.ActionBar.Menu">
<item name="android:textColor">@color/blue</item>
</style>
和使用的主题活动,我想标题是蓝色的接听/黑色
android:theme="@style/Actionbar.Music.TitleText"
也用下面的代码在该活动的创建中,其操作栏标题颜色我想成为蓝色/黑色
int titleId = getResources().getIdentifier("action_bar_title", "id",
"android");
TextView titleTv= (TextView) findViewById(titleId);
if(titleTv!= null){
titleTv.setTextColor(getResources().getColor(R.color.blue));
titleTv.setTypeface(Typeface.createFromAsset(getAssets(),
"helvetica_medium.otf"));
}