is it possible to hide the title bar(Entertainment) but not the titles of the tab views(top rated,games,movies)?
you can try for Hiding title bar
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Related
Is there any way to change the ActionBar color of fragments and change the title displayed in the ActionBar to the title of the menu option that was pressed?
If you are using AppCompat you always have to call getSupportActionBar()
Change Title :
getSupportActionBar().setTitle("Your Title");
Change Color :
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.YOUR_COLOR));
If in Fragment :
Change Title :
getActivity().getActionBar().setTitle("YOUR TITLE");
Change Color :
getActivity().getAcationBar().setBackgroundDrawable(new ColorDrawable(Color.YOUR_COLOR));
Hope this help you
This is the suggested answer written in java :
getActionBar().setTitle("Test");
getActionBar().setBackgroundDrawable(new ColorDrawable("COLOR"));
If you're using support libraries:
android.support.v7.app.ActionBar supportActionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (supportActionBar != null) {
supportActionBar.setTitle("My action bar title");
View view = new View(getContext());
view.setBackgroundColor(getResources().getColor(R.color.my_color));
supportActionBar.setBackgroundDrawable(view.getBackground());
}
Otherwise:
android.app.ActionBar actionBar = getActivity().getActionBar();
if (actionBar != null) {
actionBar.setTitle("My action bar title");
View view = new View(getContext());
view.setBackgroundColor(getResources().getColor(R.color.my_color));
actionBar.setBackgroundDrawable(view.getBackground());
}
I created an app with navigation drawer. I want to change the color of actionbar and default icon of drawer to be changed on selection of a particular navigation menu item and it should change to default values on selection of any other item.
My code
Fragment fragment;
if(fragment.toString().contains("HomeFragment")){
ab = ((BaseActivity)getApplicationContext()).getSupportActionBar();
ab.setHomeButtonEnabled(true);
ab.setDisplayHomeAsUpEnabled(true);
ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF")));
ab.setElevation(0);
ab.setDisplayHomeAsUpEnabled(true);
ab.setHomeAsUpIndicator(R.drawable.username);
}
I could change actionbar color and navigation drawer icon with the above code,but can't change to default color and icon on other navigation item selection.
Just continue your code
Fragment fragment;
if(fragment.toString().contains("HomeFragment")){
ab = ((BaseActivity)getApplicationContext()).getSupportActionBar();
ab.setHomeButtonEnabled(true);
ab.setDisplayHomeAsUpEnabled(true);
ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF")));
ab.setElevation(0);
ab.setDisplayHomeAsUpEnabled(true);
ab.setHomeAsUpIndicator(R.drawable.username);
} else {
ab = ((BaseActivity)getApplicationContext()).getSupportActionBar();
ab.setHomeButtonEnabled(true);
ab.setDisplayHomeAsUpEnabled(true);
ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("your default color")));
ab.setElevation(0);
//ab.setHomeAsUpIndicator(R.drawable.username); change it to your other icon;
}
I have implemented action bar and ab Layout with Swipeable Views. I have put a image to each title in the tabs and title. when i am changing the tab, actionbar respectively shows the tab title name in the actionbar. now I want to leave the title only from the tab header, and leave actionbar title and image on the tab header. so it will be looks like facebook app
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayUseLogoEnabled(true);
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
actionBar.addTab(actionBar.newTab().setText("Tab1").setTabListener(this)
.setIcon(R.drawable.ic_tab_pizza));
actionBar.addTab(actionBar.newTab().setText("Tab2").setTabListener(this)
.setIcon(R.drawable.ic_tab_noodle));
actionBar.addTab(actionBar.newTab().setText("Tab3").setTabListener(this)
.setIcon(R.drawable.ic_tab_slides));
actionBar.addTab(actionBar.newTab().setText("Tab4").setTabListener(this)
.setIcon(R.drawable.ic_tab_promotion));
actionBar.addTab(actionBar.newTab().setText("Tab5").setTabListener(this)
.setIcon(R.drawable.ic_tab_profile));
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// set background for action bar tab
bar.setStackedBackgroundDrawable(new ColorDrawable(Color
.parseColor("#ffffff")));
bar.show();
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
getActionBar().setTitle(tab.getText());
viewPager.setCurrentItem(tab.getPosition());
}
Hello I am using Sherlock library to achieve the Tabs. Here I am looking to remove the ActionBar at the top and set the custom title layout instead of it.
I achieved a functionality to add the Tabs but could not set the custom title over ActionBar. Any way to do this ?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pay_stub);
// adding action bar tabs to the activity
ActionBar mActionBar = getSupportActionBar();
Tab firstTab = mActionBar.newTab().setText(getString(R.string.paystub_current_tab)).setTabListener(this);
Tab secondTab = mActionBar.newTab().setText(getString(R.string.paystub_all_tab)).setTabListener(this);
// add the tabs to the action bar
mActionBar.addTab(firstTab);
mActionBar.addTab(secondTab);
// set the navigation mode the Action Bar Tabs
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}
Thanks in advance.
I resolved this by adding background color and icon of the ActionBar.
ActionBar actionBar = getSupportActionBar();
setTitle("");
actionBar.setIcon(R.drawable.headerlogo);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F4A401")));
I want to set the actionbar icon and title to be visible for an activity.
My app theme turns them off:
// styles.xml
<item name="android:displayOptions"></item>
In my activity:
public void onCreate() {
...
ActionBar actionBar = activity.getActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setIcon(R.drawable.ic_launcher);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
The title and up arrow appear. But I can't get the icon to appear. What am I doing wrong?
You are missing setDisplayShowHomeEnabled().