Android 如何使用单行布局更改ActionBar选项卡文本颜色?
有两行布局,看ActionBar选项卡,文本颜色为蓝色 这是单线布局,texColor是白色的,你怎么能做到呢Android 如何使用单行布局更改ActionBar选项卡文本颜色?,android,android-layout,android-actionbar,Android,Android Layout,Android Actionbar,有两行布局,看ActionBar选项卡,文本颜色为蓝色 这是单线布局,texColor是白色的,你怎么能做到呢 1要更改选项卡样式,您不能使用actionBar.newTab.setTextxxx,因为您无法获取TextView,因此必须创建TextView,然后使用actionBar.newTab.setCustomViewtabView 2查看R.attr.actionBarTabTextStyle属性,必须在attrs.xml中写一行 //attrs.xml <attr name="
1要更改选项卡样式,您不能使用actionBar.newTab.setTextxxx,因为您无法获取TextView,因此必须创建TextView,然后使用actionBar.newTab.setCustomViewtabView 2查看R.attr.actionBarTabTextStyle属性,必须在attrs.xml中写一行
//attrs.xml
<attr name="actionBarTabTextStyle" format="reference"/>
4 ActionBar有一个私有字段:mHasEmbeddedTabs,当一行为true,另一行为false时,只需获取该字段的值
private boolean mHasEmbeddedTabs =true;
@Override
public void onCreate(Bundle savedInstanceState) {
try {
Field field = actionBar.getClass().getDeclaredField("mHasEmbeddedTabs");
field.setAccessible(true);
this.mHasEmbeddedTabs=field.getBoolean(actionBar);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
5现在,当操作栏和选项卡在一行中时,我可以更改选项卡文本的颜色
if(this.mHasEmbeddedTabs){
tabView.setTextColor(getResources().getColor(R.color.white));
}
在宽屏幕中,选项卡将移动到操作栏automatically@y.feizi我知道,但我不知道什么时候发生,我想改变文本颜色,不需要知道!只为laout land文件夹中的宽屏幕设计布局!安卓检测到了吗automatically@y.feizi在我的表格2048×1536p,7.9英寸,laout land和laout port都是单线布局。你必须搜索两个东西!第一:如何检测屏幕大小,第二,如何改变动作栏的文字颜色!
// MainActivity
TextView tabView=createTab(tabTitle);
ActionBar.Tab actionBarTab=actionBar.newTab();
actionBarTab.setCustomView(tabView).setTabListener(this)
actionBar.addTab(actionBarTab);
private boolean mHasEmbeddedTabs =true;
@Override
public void onCreate(Bundle savedInstanceState) {
try {
Field field = actionBar.getClass().getDeclaredField("mHasEmbeddedTabs");
field.setAccessible(true);
this.mHasEmbeddedTabs=field.getBoolean(actionBar);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
if(this.mHasEmbeddedTabs){
tabView.setTextColor(getResources().getColor(R.color.white));
}