If I understand correctly, the purpose of this widget is to make toolbar compatible with older versions of android (like 4.x), but for some reason when I run my app on actual device with android 4.x I'm not seeing my toolbar. And in emulator with Android 6 everything is ok.
I'm using @style/Theme.AppCompat.Light.NoActionBar in my theme and my activity extends AppCompatActivity.
This is how my toolbar looks like:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
Included in my activity xml:
<include
android:id="@+id/tool_bar"
layout="@layout/actionbar_main"></include>
And added in activity code on create:
toolbar = (Toolbar) findViewById(R.id.tool_bar);
this.setSupportActionBar(toolbar);
Any hint why this not showing on android 4.x?
Please Try This.
Change your XML Layout as.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".HomeActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With