ActionBar is not visible with Coordinator Layout

1.5k Views Asked by At

In my App, there is an activity which has a layout as the one posted below. the problem I have is, when that activity starts, action bar becomes invisible, CoordinatorLayout takes up all the screen. What I am trying to do is that actionBAr should be visible. The action bar of the my App looks like the image shown in section "action bar" below.

To solve this problem I did the following:

i added "FloatingButtonTheme" to the styles.xml file as shown below in "styles.xml". and in the manifest file I added the following code:

<activity 
    android:name="x.xx.xxx.activity.ListeActivity"
    android:theme="@style/FloatingButtonTheme">

but the result I got is that the activity takes up all the space on the screen with floating button appearing but the action bar is never there.

Please let me know how to force my action bar just as in picture below to show up?

Actually, this problem only appears when I use the

activity layout:

<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="wrap_content"
    android:fitsSystemWindows="true"
    tools:context=".activity.VersiecherungsListeActivity">

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/versicherungslisteactivity_fab_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="10dp"
        android:src="@android:drawable/ic_input_add"
        app:backgroundTint="@color/light_orange" />

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

action bar:

enter image description here

sytles:

<style name="AppBaseTheme" parent="android:Theme.Holo.Light">

</style>

<style name="AppTheme" parent="AppBaseTheme">

</style>
<style name="FloatingButtonTheme" parent="Theme.AppCompat.Light.DarkActionBar">

</style>
3

There are 3 best solutions below

0
Amrmsmb On BEST ANSWER

i just added android:theme="@style/Theme.AppCompat.Light.DarkActionBar" to the CoordinatorLayout as shown below:

<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=".activity.VersiecherungsListeActivity"
    android:theme="@style/Theme.AppCompat.Light.DarkActionBar">

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/versicherungslisteactivity_fab_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="10dp"
        android:src="@android:drawable/ic_input_add"
        app:backgroundTint="@color/light_orange" />

</android.support.design.widget.CoordinatorLayout>
3
Ravish Sharma On

Add Tool Bar below coordinator layout :

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways" />

And in activity

ToolBar toolbar =(ToolBar)finfViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
5
Gidi Sprintzin On

Add appbar and toolbar to your xml, or just toolbar:

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


        <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/AppTheme.PopupOverlay" />

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