【发布时间】:2014-02-17 12:41:52
【问题描述】:
我正在尝试以编程方式更改操作栏选项卡的颜色。默认情况下,我在 styles.xml 中将它们设置为红色,这就是我希望它们与 viewpager 中的其他选项卡一起使用的方式,但是,在第一个选项卡上,我希望操作栏和导航选项卡都变得透明。我已经使用此代码在操作栏上完成了此操作
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
// When the given tab is selected, switch to the corresponding page in
// the ViewPager.
int newActionBarColor/*, newActionBarTabColor*/;
if(tab.getPosition() == 0) {
newActionBarColor = Color.parseColor("#" + Integer.toHexString(getResources().getColor(R.color.actionBarTransparent)));
//newActionBarTabColor = Color.parseColor("#" + Integer.toHexString(getResources().getColor(R.color.actionBarTabsTransparent)));
} else {
newActionBarColor = Color.parseColor("#" + Integer.toHexString(getResources().getColor(R.color.actionBar)));
//newActionBarTabColor = Color.parseColor("#" + Integer.toHexString(getResources().getColor(R.color.actionBarTabs)));
}
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(newActionBarColor));
//getSupportActionBar().setStackedBackgroundDrawable(new ColorDrawable(newActionBarTabColor));
//getSupportActionBar().setSplitBackgroundDrawable(new ColorDrawable(newActionBarTabColor));
mViewPager.setCurrentItem(tab.getPosition());
}
但我无法使用选项卡进行此操作,有什么想法吗?你可以看到我上面的尝试。
我想要彩色标签的标签上的活动:
我希望操作栏和选项卡都透明的选项卡上的当前内容:
【问题讨论】:
标签: android android-activity tabs navigation android-viewpager