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);
Related
This is the by default coded navigation drawer activity and i can't find the actionbardrawertoggle code . I implemented the search cardview over the appbar and under drawertoggle icon But, the cardview is not settled fully over the app bar under navdrawer icon.
enter image description here
Adding a search view is actually very easy in Android as it has inbuilt support for it. Go through the Search view functionality provided by android for more details.
https://developer.android.com/guide/topics/search/search-dialog.html
Currently my custom toolcontrols are outside the toolbars because of the scaling issue in E4. Toolbar does not scale correctly in E4
Now my client want to have different toolbars for all the toolcontrols, so that the user can rearange the order of the toolbar and separate the toolcontrols from each others. How is this possible in E4? I know the toolcontrols inside the toolbar is not scaling the toolbar itself. But is there any workaround to place a toolcontrol inside a toolbar?
I added ahidden icon to the toolbar when adding the custom toolcontrol to it. Eclipse scales the toolbar correct know.
I'm a bit of an Android newbie. I have a toolbar on my MainActivity which has a home button on the left (backarrow). I'm setting it like this
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
activity.setSupportActionBar(toolbar);
activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
I noticed that on other Android apps when I hit the home button it will change background color momentarily to show the user that the click has been registered, and this is what I want to achieve. How can I do this? Is it a simple config change or is it something I have to implement myself?
Thanks for any help!
I'm using android support design library to create a collapsing toolbar. It works great, my view collapses when I scroll and expands when I scroll back.
But I wonder, I would like to have a profile in this toolbar, but half the profile would be hidden at first. So for example at first you only see the users profile picture in the toolbar. If you scroll down the list the toolbar collapses and everything gets hidden. But if you scroll the other way, to the top of the list and kind of beyond, the toolbar will expand even more and show you both profile picture and more information like name, description and so on..
Is this possible? To set the toolbar like "half collapsed" or something similar.
After a lot of trying and searching for information about the collapsing toolbar I ended up using another library instead.
https://github.com/umano/AndroidSlidingUpPanel
With this I got the customisation I wanted by setting anchor points. Though I didn't get, or atleast I don't know how to get, the function of the toolbar expanding and changing from toolbar color to an image for example. But for my case, the customisation was the main function and thus more important.
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