Alok
Alok

Reputation: 163

ActionBar not visible on Android KitKat

I am trying to implement Toolbar using android design library. The Output works as expected on Lollipop and Marshmallow devices but it does not show ToolBar on Kitkat devices.

I have seen similar posts on stack overflow(here_1,here_2) and tried to implement the changes listed. However, I am unable to get this working on Kit Kat devices.

I have included the following in my build.gradle file:

compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'

Here is my main_Activity.xml file:

<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    android:theme="@style/Theme.MyMovie"
    tools:context=".MainActivity">


    <include layout="@layout/include_grid_viewpager"/>


    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_view"/>

</android.support.v4.widget.DrawerLayout>

Here is my include_grid_viewpager.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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Chalisa">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        >

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

    </android.support.design.widget.AppBarLayout>

    <GridView
        android:id="@+id/gridview1"
        android:columnWidth="80dp"
        android:paddingTop="?attr/actionBarSize"
        android:gravity="center_horizontal"
        android:background="@drawable/stroke"
        android:numColumns="3"
        android:stretchMode="spacingWidthUniform"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </GridView>

</android.support.design.widget.CoordinatorLayout>

and Here is my style.xml file

<resources>

    <style name="Theme.Mytheme" parent="Base.Theme.DesignDemo">
    </style>

    <style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#FF0000</item>
        <item name="colorPrimaryDark">#FC1501</item>
        <item name="colorAccent">#FF0000</item>
        <item name="android:windowBackground">@color/window_background</item>
        <item name="android:textSize">16sp</item>
    </style>

    <style name="Widget.CardContent" parent="android:Widget">
        <item name="android:paddingLeft">16dp</item>
        <item name="android:paddingRight">16dp</item>
        <item name="android:paddingTop">24dp</item>
        <item name="android:paddingBottom">24dp</item>
        <item name="android:orientation">vertical</item>
    </style>

</resources>

Here is my manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="aps.com.nap" >

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Mytheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".DetailData"
            android:parentActivityName=".MainActivity"
            android:screenOrientation="portrait"/>
        <activity android:name=".myDetail"
            android:parentActivityName=".MainActivity"
            android:screenOrientation="portrait"/>

    </application>

</manifest>

I have spent more than 4 hours digging through internet and stack overflow responses. I believe I am making some minor mistake in my XML.

Request you all to provide any information that will help me resolve this Issue at the earliest.

Thank you for all the help.

Upvotes: 1

Views: 2552

Answers (3)

Taeho Kim
Taeho Kim

Reputation: 1845

I have got the same problem. In my case, appending dummy view before AppBarLayout solved the problem.

Following is my own case:

[Before]

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/eya_fl_activity_viewer_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ProgressBar
            android:id="@+id/eya_pb_activity_base_viewer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="?attr/actionBarSize"
            android:visibility="gone" />

    </FrameLayout>

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

        <include layout="@layout/lzc_toolbar" />

    </android.support.design.widget.AppBarLayout>

    <!-- Other views... -->

</android.support.design.widget.CoordinatorLayout>

[After]

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Dummy view -->
    <FrameLayout
        android:id="@+id/eya_fl_activity_viewer_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

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

        <include layout="@layout/lzc_toolbar" />

    </android.support.design.widget.AppBarLayout>

    <!-- Other views... -->

</android.support.design.widget.CoordinatorLayout>

Upvotes: 1

Alok
Alok

Reputation: 163

I had to change my include_grid_viewpager.xml as follows to get it working. moved the grid inside the AppBar Layout, so that it is below the action bar. The grid view was overlaying the action bar.

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

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        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/toolbar1"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_scrollFlags="scroll|enterAlways"
            />

        <GridView
            android:id="@+id/gridview1"
            android:columnWidth="110dp"
            android:gravity="center_horizontal"
            android:background="@drawable/stroke"
            android:numColumns="3"
            android:stretchMode="spacingWidthUniform"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </GridView>

    </android.support.design.widget.AppBarLayout>



</android.support.design.widget.CoordinatorLayout> 

Thank you for all the support.

Upvotes: 6

BNK
BNK

Reputation: 24114

Please review inside onCreate() of your activity, have you called the following yet?

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar1);
setSupportActionBar(toolbar);

Moreover, post your AndroidManifest.xml for more info.

Upvotes: 0

Related Questions