Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom support.v7.widget.Toolbar not showing on device

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?

like image 671
ShP Avatar asked Nov 05 '15 01:11

ShP


1 Answers

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>
like image 71
Mr Robot Avatar answered Sep 29 '22 12:09

Mr Robot