这是我的代码。如何在这个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));
}
}
答案 0 :(得分:1)
您可以创建一个标签布局,其中每个标签都有一个自定义textView,并使用您选择的颜色在tablayout中添加该标签
View customView = LayoutInflater.from(getContext()).inflate(R.layout.tab_text, null);
addTab(newTab().setCustomView(customView));