Toolbar vs appcompat v7-21 toolbar - android

What is the difference between the two? what all features are included in toolbar thats not in v7-21 toolbar? What all limitations are there in using v7-21 tollbar in place of toolbar?

If you look at the documentation for the Toolbar and the AppCompat Toolbar you can see that functionally, there aren't any differences between the two. Of course the SDK level required differs between the two and to use the Toolbar you have to call setActionBar(mToolbar); but with the support Toolbar you have to call setSupportActionBar(mToolbar);

Related

what is the difference between standalone toolbar and toolbar as action bar?

I am little bit confuse about standalone toolbar & toolbar as actionbar.
Standalone toolbar can do the work of toolbar as actionbar then what is the need of toolbar as actionbar ?
take a peek at the documentation for android toolbar and notice that toolbar is portable and generic.
A Toolbar is a generalization of action bars for use within application layouts. While an action bar is traditionally part of an Activity's opaque window decor controlled by the framework, a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy.

Remove Toolbar as actionbar after using setSupportActionBar

I have a toolbar that was set up using setSupportActionBar();, so at some point i want the toolbar not to be the actionbar again.
So is there anyway you can remove a toolbar as actionbar after setting it up using setSupportActionBar.
Then just try hiding the toolbar view when it is not needed...

Adding a custom Toolbar to a FragmentActivity (that uses a ViewPager)?

I'm using a ViewPager to slide across 3 screens at the moment, which is initialised in a FragmentActivity.
My aim is to have a Toolbar or ActionBar that remains the same for each page in the ViewPager - apart from the title, which changes depending on the page you are on.
Does anybody know how I can achieve this?
I have tried the following
mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar);
setActionBar(mActionBarToolbar);
getActionBar().setTitle(mViewPager.getCurrentItem());
But I keep getting an error setActionBar (android.widget.Toolbar) in Activity cannot be applied to android.widget.support.v7.Toolbar.
Any ideas?
When using the support libraries, you need to use the support methods.
mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mActionToolbar);
getSupportActionBar().setTitle(mViewPager.getCurrentItem());
You should be golden if you replace your code to the code above.

how to set the NavigationMode in the ActionBar

When I tried to use ActionBar and specify the navigationMode eclipse says it is deprecated without suggesting the recommende one to use instead.
what should i use instead of this.actionBar.setNavigationMode(mode)?
There is no alternate method to use from the now deprecated setNavigationMode since the Toolbar is basically a stripped down version of the actionbar where you put in the views you want inside the toolbar.
for example if you wanted to replicate the Dropdown navigation mode you would put a spinner inside your toolbar

Use pre-existing Action Bar styles to style the toolbar

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 Toolbars to handle this logic automatically.
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.

Categories

Resources