工具栏在android 4.4平板电脑中不可见

工具栏在android 4.4平板电脑中不可见,android,android-layout,android-coordinatorlayout,Android,Android Layout,Android Coordinatorlayout,我在这里有以下布局,我正在添加一个工具栏。在安卓6.0手机中,一切看起来都很好。我刚刚在安卓4.2平板电脑上试用过,但没有看到工具栏。以下是我的布局: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="htt

我在这里有以下布局,我正在添加一个工具栏。在安卓6.0手机中,一切看起来都很好。我刚刚在安卓4.2平板电脑上试用过,但没有看到工具栏。以下是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<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="com.android.sushil.omdbclient.ui.main.MoviesList.MoviesListActivity">

    <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:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ProgressBar
            android:id="@+id/main_progress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:layout_gravity="center"/>

        <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/windowBackground"
            android:paddingTop="?attr/actionBarSize"
            android:visibility="visible">

        </android.support.v7.widget.RecyclerView>

        <TextView
            android:id="@+id/message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="@string/search_to_begin"
            android:textSize="16sp"
            android:visibility="visible" />

        <!--<include layout="@layout/error_layout"/>-->
    </RelativeLayout>

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

如果使用Linearlayout更改协调器布局,则可以看到工具栏。但是有人能告诉我如何在不使用Linerlayout替换协调器布局的情况下修复此问题吗


感谢您的帮助。

您可以尝试在android清单中为您的活动声明android主题

例如:

  <activity android:name=".activities.MainActivity"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:screenOrientation="portrait">
            </activity>

在工具栏样式中添加这些属性

<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowActionBarOverlay">false</item>
    <item name="windowNoTitle">true</item>
</style>
</resources>

假的
假的
真的

您的
AppBarLayout
被您的
RelativeLayout
遮住了

从协调人布局文件中:

CoordinatorLayout是一个超级强大的框架布局

FrameLayout
将按定义顺序绘制子对象。因此,首先绘制
AppBarLayout
,然后绘制
RelativeLayout
。因为您的
RelativeLayout
具有
match\u parent
的宽度和高度,所以它会填充整个屏幕

所以问题是为什么这只发生在某些API级别上,因为我的描述似乎应该适用于任何API级别

事实证明,
CoordinatorLayout
FrameLayout
聪明一点,在较新的API级别上,它可以做一些特殊的事情来确保您的
AppBarLayout
可见。在较旧的API级别上,默认情况下无法执行此操作

但是,您可以通过在
标记中添加
app:layou-behavior
attr来解决此问题。只要改变这个:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

为此:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">


此属性将触发智能行为,以确保您的
AppBarLayout
始终可见,即使在较旧的API级别上也是如此。

我正在从布局文件添加工具栏。因此,我已将主题设置为NoActionBar@Sushil对您可以尝试只在清单中声明,而不在布局中声明。我有它们,但仍然存在问题