【问题标题】:ActionBar is not visible with Coordinator LayoutActionBar 在协调器布局中不可见
【发布时间】:2016-11-30 09:59:35
【问题描述】:

在我的应用程序中,有一个活动,其布局如下所示。我遇到的问题是,当该活动开始时,操作栏变得不可见,CoordinatorLayout 占据了所有屏幕。 我想要做的是 actionBAr 应该是可见的。我的应用程序的操作栏看起来像下面“操作栏”部分中显示的图像。

为了解决这个问题,我做了以下操作:

我在styles.xml 文件中添加了“FloatingButtonTheme”,如下面的“styles.xml”所示。在清单文件中我添加了以下代码:

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

但我得到的结果是,活动占据了屏幕上的所有空间,浮动按钮出现,但操作栏永远不存在。

请告诉我如何强制显示我的操作栏,如下图所示?

其实这个问题只有在我使用的时候才会出现

活动布局

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

操作栏

风格

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

</style>

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

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

</style>

【问题讨论】:

  • 发布此布局代码versicherungslisteactivity_vers_view??
  • @Ironman 好的,我添加了它
  • 你会删除 android:fitsSystemWindows="true"
  • @user2121 add Toolbar as Ravish Sharma 回答如果你没有添加在Activity中。

标签: android android-actionbar android-coordinatorlayout android-actionbar-compat android-actionbaractivity


【解决方案1】:

在协调器布局下方添加工具栏:

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

在活动中

ToolBar toolbar =(ToolBar)finfViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

【讨论】:

  • 我应该将它添加到“android.support.design.widget.AppBarLayout”中吗?或者我应该删除“android.support.design.widget.AppBarLayout”??
  • 是的,您可以将其添加到应用栏布局中,也可以将其添加到协调器布局下方,这完全取决于您的布局行为
  • 你是在处理 Tab 布局还是告诉我别的什么?
【解决方案2】:

我刚刚将 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>

【讨论】:

    【解决方案3】:

    appbartoolbar 添加到您的xml,或者只是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>
    

    【讨论】:

    • 但是 app:popupTheme="@style/AppTheme.PopupOverlay" 没有定义
    • 您是否尝试删除它?或添加:&lt;style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /&gt; 到您的 style xml
    • 关于“android:theme="@style/AppTheme.AppBarOverlay"..找不到与给定名称匹配的资源
    • 您是否打开了您的styles.xml 文件并添加了该行:&lt;style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /&gt;
    • “@style/AppTheme.AppBarOverlay”怎么样??也没有找到与给定名称匹配的资源
    猜你喜欢
    • 2023-03-06
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多