简体   繁体   English

ActionBar在协调器布局中不可见

[英]ActionBar is not visible with Coordinator Layout

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. 我的问题是,当该活动开始时,操作栏变得不可见,CoordinatorLayout占据了所有屏幕。 What I am trying to do is that actionBAr should be visible. 我正在尝试做的是actionBAr应该可见。 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". 我在styles.xml文件中添加了“ FloatingButtonTheme”,如下面的“ 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 : 动作栏

在此处输入图片说明

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>

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);

i just added android:theme="@style/Theme.AppCompat.Light.DarkActionBar" to the CoordinatorLayout as shown below: 我刚刚将android:theme =“ @ style / Theme.AppCompat.Light.DarkActionBar”添加到CoordinatorLayout中,如下所示:

<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>

Add appbar and toolbar to your xml, or just toolbar : appbartoolbar添加到您的xml中,或者仅将toolbar添加到您的XML中:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM