[英]How to change tab indicator color and text color while swiping tab using ViewPager?
這是我的代碼。 如何在此Java類中添加Tabindicator顏色和文本顏色?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false); // hides action bar icon
actionBar.setDisplayShowTitleEnabled(false); // hides action bar title
LayoutInflater mInflater = LayoutInflater.from(this);
mCustomView = mInflater.inflate(R.layout.custom_menu, null);
i = (ImageButton)mCustomView.findViewById(R.id.imageButton);
actionBar.setDisplayShowCustomEnabled(true);
e = (EditText)mCustomView. findViewById(R.id.editText1);
e.setVisibility(mCustomView.INVISIBLE);
TabAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
Tab = (ViewPager)findViewById(R.id.pager);
Tab.setOnPageChangeListener(
new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar = getActionBar();
actionBar.setSelectedNavigationItem(position);
}
});
Tab.setAdapter(TabAdapter);
// Tab.showContextMenu();
actionBar = getActionBar();
//Enable Tabs on Action Bar
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// set background for action bar tab
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF")));
actionBar.show();
ActionBar.TabListener tabListener = new ActionBar.TabListener(){
@Override
public void onTabReselected(android.app.ActionBar.Tab tab,
FragmentTransaction ft) {
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
Tab.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(android.app.ActionBar.Tab tab,
FragmentTransaction ft) {
// TODO Auto-generated method stub
}};
//Add New Tab
actionBar.addTab(actionBar.newTab().setText("SPOTLIGHT").setTabListener(tabListener));
actionBar.addTab(actionBar.newTab().setText("WHAT'S NEW").setTabListener(tabListener));
actionBar.addTab(actionBar.newTab().setText("HOT ITEMS").setTabListener(tabListener));
}
}
您可以創建一個選項卡布局,其中每個選項卡都有一個自定義textView,然后使用您選擇的任何顏色將該選項卡添加到選項卡布局中
View customView = LayoutInflater.from(getContext()).inflate(R.layout.tab_text, null);
addTab(newTab().setCustomView(customView));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.