4
我试图以编程方式更改操作栏选项卡的颜色。我默认在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());
}
但我不能得到这与标签,任何想法的工作?你可以看到我上面试过的东西。
活动的标签,我想有色标签:
目前,我有,我想无论是动作栏和标签为透明标签上什么:
这不会改变任何内容,我不知道方式。我将其完全复制到它,并将它保留为默认颜色,当它将它设置为红色时。 –
在此期间,我找到了以下链接可以帮助你:'http:// jgilfelt.github.io/android-actionbarstylegenerator /' –
如果它对你有帮助,你可以使用upvote这个答案吗? –