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這個答案嗎? –