Android Toolbar: Title And Overflow Menus Aligment Issue On 5.0 Only
Solution 1:
I eventually came up with the solution to my problem; I'm sharing it for whoever faces the same issue. I realized the toolbar is only needed for pre-Lollipop devices, so I created two different Themes for the application: one WITHOUT the ActionBar in style.xml resource, and one WITH the ActionBar in v21 version of the style resource. Into style.xml:
<stylename="AppTheme"parent="Theme.AppCompat.NoActionBar">
...
</style>
Into v21/style.xml:
<stylename="AppTheme"parent="Theme.AppCompat">
...
</style>
This way, whenever a pre-Lollipop device launches the app, it will launch the ActionBar-less version. Changes are needed in the Activity layout and class as well: as for style, I created a v21 version of the Activity layout for Lollipop devices and included the Toolbar in the original layout only: into layout/activity_main.xml
<RelativeLayout...><includeandroid:id="@+id/toolbar"layout="@layout/toolbar" />
...
Finally, into OnCreate method inserted this conditional:
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Toolbartoolbar= (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
in order to fill up the empty ActionBar on pre-Lollipop devices only. I tried the application on both my devices and it finally worked. Note that for v21 version of an xml resource I mean a copy of the original file, saved into "resource_type"-v21 folder.
Post a Comment for "Android Toolbar: Title And Overflow Menus Aligment Issue On 5.0 Only"