Reputation: 3457
I'm in the process of migrating an app from AppCompat-v20 to AppCompat-v21. As part of that process, I'm trying to move away from the Action Bar, and replace it with a Toolbar
so we can take advantage of all the new Material design goodness.
Previously, we had defined all of the information about the AB's displayOptions in a style, and then we set that style as the actionBarStyle
in the Activity's theme. However, now that I'm extending Theme.AppCompat.NoActionBar those properties aren't respected anymore, which makes sense, because my theme extends Theme.AppCompat.NoActionBar
. At the same time, I would still like to have those displayOptions
be applied in the same places they were before (i.e. I'd like to be able to specify whether I want to use a logo or show home as part of the theme).
I know I can probably do this by putting displayOptions
onto the theme and parsing them myself, but I'm wondering if there's any support within AppCompat for Toolbar
s to handle this logic automatically.
Upvotes: 3
Views: 344
Reputation: 38856
With the Toolbar
what you have to remember is that it is basically just a view group so you can customize it a lot easier and more so than you could with the ActionBar
. That being said, you can use styles to alter the appearance of the Toolbar
however there are methods for settings things like title/logo/navigation.
Here's an example of styling your Toolbar
:
<android.support.v7.widget.Toolbar
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
If you are using ActionBarActivities
and Fragments
then you can call the following to let Android know to use your Toolbar
as the supportActionBar. This means that all of your calls to getSupportActionBar()
will still be valid.
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
The new Material Design guidelines have started to move away from using Logos but if you insist on settings one you can like so:
toolbar.setLogo();
Your question was slightly vague so for more info checkout this post by Chris Banes and Nick Butcher and then the documentation.
Upvotes: 4