Many suggested that I should use:
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
and it shows me an actionbar with no title but with the application logo.
It was also suggested that I hide the logo and, when I did, the actionbar appeared empty and didn't hide.
duplicate question , see :
Android: Hide ActionBar, keep Tabs , Only display tabs in action bar
Android: How do you hide Tabs in the ActionBar?
You can hide the action bar at runtime by calling hide(). For example:
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
Full documentation
Related
For my App i need to show icon in toolbar. So I referred a question on stackoverflow
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
I applied the same to my code but after running the app i noticed my navigational drawer icon i.e. hamburger gone missing.
How can i get it back along with the app icon?
Remember, ToolBar is the more customizable version of ActionBar, and are two different things, though they basically follow the same pattern.
My answer is to user Toolbar and customize it for the required view instead of using the default ActionBar.
If you are using the customized ToolBar, then the below code is not going to work.
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
Use ToolBar.
Change from this
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
To
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_launcher);
I am using the ObservableScrollView library to show and hide the ActionBar as you are scrolling up and down an activity. This works well but when the ActionBar is animating sliding in or out a blank area at the bottom of the screen about the size of the ActionBar is briefly pushed up.
After searching similar issues the suggested solution is to the following line to onCreate():
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
This has had no visible effect and the issue is still present.
Solved by setting my ActionBar to overlay content in the XML style.
I've been searching on how to make transparent actionbar in fragment and no answer so far. So, the scenario is, I create an app using Navigation Drawer, each menu refer to same actionbar in MainActivity.
But I can't customize actionbar in transparent mode, like this Transparent Actionbar: custom tabcolor. In this:
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));
that code had to before setContentView, and as you know on the fragment we use onCreateView for the layout.
How can I achieve the transparent actionbar in fragment?
if you just want to make transparent Actionbar then you can do it by this way in Fragment's onCreateView
getActivity().getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#33000000")));
Use a Toolbar and use the following code to let it behave like Action bar
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
To include toolbar in your layout use the following.
<android.support.v7.widget.Toolbar
android:id=”#+id/my_awesome_toolbar”
android:layout_height=”wrap_content”
android:layout_width=”match_parent”
android:minHeight=”?attr/actionBarSize”
android:background=”?attr/colorPrimary” />
It is a lot easy to change transparency of Toolbar as compared to dealing with ActionBar
Once set you can deal with toolbar as any other view i.e. changing transparency/color dynamically is a lot easy for Toolbar
I have done some research, looked at this question but it didn't have the answers I was looking for.
Change Action Bar onPressed color.
It is doing the same thing but is not what I am looking for, as I want to set the action bar color programatically, as I need to change the color by user preference. Here is how I get the action bar
ActionBar bar = getActionBar();
Any help with setting the color for when the back button or an item in the menu is tapped would be great. Thanks :)
to change actionbar background, try this
bar.setBackgroundDrawable(new ColorDrawable(0xff00DDED));
Put this code into your oncreate method:
ActionBar actions = getActionBar();
actions.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FF3300")));
I want to overlay the action bar and also hide the title bar.I have tried this
requestWindowFeature(Window.FEATURE_NO_TITLE);
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY );
But both is not working ,only one of the feature is working at a time.Any suggestion?
Try assigning the actionbar into a variable first... you can then use that variable to do anything you want e.g
ActionBar actionBar = getActionBar();
actionBar.hide();
For androidbar overlay create a custom android bar theme. See https://developer.android.com/training/basics/actionbar/overlaying.html