I want to change my ActionBar's Tabs background color with tabs selector line at bottom color.
I want to do that by using java code not xml.
I have tried creating ActionBar tabs ..
actionBar = getActionBar();
// Hide the action bar title
ActionBar actionBar.setDisplayShowTitleEnabled(false);
// Enabling Spinner dropdown navigation
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab PlayerTab = actionBar.newTab().setText("Fragment A");
ActionBar.Tab StationsTab = actionBar.newTab().setText("Fragment B");
//create the two fragments we want to use for display content
//////////////////////// Fragment PlayerFragment = new AFragment();
/////////////////// Fragment StationsFragment = new BFragment();
//set the Tab listener. Now we can listen for clicks.
///////////////////PlayerTab.setTabListener(new MyTabsListener(PlayerFragment));
///////////////// ////StationsTab.setTabListener(new MyTabsListener(StationsFragment));
//add the two tabs to the actionbar
actionBar.addTab(PlayerTab);
actionBar.addTab(StationsTab);
Now when I try to set background color with tabs line selector color, I get the error Java.lang.NullPointException
My OnTabSelcted() method ..
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
RelativeLayout tabLayout = (RelativeLayout) tab.getCustomView();
//tab.setCustomView(getResources().getDrawable(R.drawable.tabs_selector_blue));
System.out.println("Tab position is " +tab.getPosition());
try{
if(tab.getCustomView() == null){
tabLayout.setBackgroundResource(TABS_BACKGROUND[tab.getPosition()]);
tab.setCustomView(tabLayout);
}else{
Toast.makeText(getApplicationContext(), "check for tabs", Toast.LENGTH_SHORT).show();
}
}catch(Exception e){
e.printStackTrace();
}
}
I have defined a custom selector for background and need to inflate it.
I am getting on line tabLayout.setBackgroundResource(TABS_BACKGROUND[tab.getPosition()]);
Please let show me where's my error.