Mehdi Karimi
Mehdi Karimi

Reputation: 528

ActionBar is Empty

The app is correct in android 5 and 6
but under android 5 , the action bar is Empty (with no app name & navigation button) just a blank actionbar.

this is xml file :

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        app:tabGravity="center"/>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /></android.support.design.widget.CoordinatorLayout>

and the style file is :

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">#FF0997B9</item>
    <item name="colorPrimaryDark">#096e86</item>
    <item name="colorAccent">#00f6ff</item>
</style>
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

it should look like this :
enter image description here

but in under android 5 it's like this :
enter image description here

Upvotes: 1

Views: 1095

Answers (2)

Mehdi Karimi
Mehdi Karimi

Reputation: 528

Actually it was because of the app_bar_main.xml
Toolbar tag was written in 2 places. one of them in main activity and one of them in app_bar_main.xml that android Studio create it itself ...

Upvotes: 0

Myth
Myth

Reputation: 1258

In your onCreate method:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if(toolbar != null) {
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("My custom toolbar!");
        ...
    }

In your manifest file:

android:theme="@style/AppTheme.NoActionBar"

Upvotes: 1

Related Questions