Nougat中如何实现导航抽屉在状态栏上方显示?

9
我尝试在我的应用程序中构建导航抽屉,导航抽屉在以前的Nougat版本中运行良好,但在Nougat中,导航抽屉不会覆盖状态栏。我尝试了很多解决方案,但在Nougat中没有起作用,请帮忙!
这是我的activity_main.xml文件:
 <android.support.v4.widget.DrawerLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/drawerLayoutId"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <RelativeLayout
        android:fitsSystemWindows="true"    
        android:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    
        tools:context="com.example.pushpam.helloworld.MainActivity">
    
        <include
            layout="@layout/custom_tool_bar"
            android:id="@+id/customtollbarimportid"/>
    
        <TextView
            android:textSize="80dp"
            android:textColor="#E9CC0014"
            android:text="I"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/customtollbarimportid"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="65dp"
            android:layout_marginStart="65dp"
            android:layout_marginTop="79dp"
            android:id="@+id/textView" />
    
        <TextView
    
            android:textSize="80dp"
            android:textColor="#E9CC0014"
            android:text="Love"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView2"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true" />
    
        </RelativeLayout>
    
    <fragment
        android:fitsSystemWindows="true"
        android:id="@+id/nav_drawer_fragment_id"
        android:layout_width="280dp"
        android:layout_height="match_parent"
        app:layout="@layout/fragment_navigationfragment"
        android:layout_gravity="start"
        android:name="com.example.pushpam.helloworld.navigationfragment"
        tools:layout="@layout/fragment_navigationfragment" />
        
    </android.support.v4.widget.DrawerLayout>

我的styles.xml文件:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

</style>

<style name="CustomToolBarTheme">

    <item name="android:textColorPrimary">@color/toolBarTextColor</item>
    <item name="android:textColorSecondary">@color/toolBarTextColor</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

和 Styles(v21).xml

<resources>

    <style name="CustomToolBarTheme">
        <item name="android:textColorPrimary">@color/toolBarTextColor</item>
        <item name="android:textColorSecondary">@color/toolBarTextColor</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:windowTranslucentStatus">true</item>
    </style>
</resources>

my current navigation drawer

这是我的当前导航抽屉,我希望它覆盖在状态栏上方。

发布您的状态图片 - Charuක
@Charuka 请查看。 - xyz rety
你给状态栏加了颜色吗?抽屉在其后面,我猜。 - Charuක
我对类似用例的回答:https://stackoverflow.com/a/59405510/9079028 - Abhishek Garg
2个回答

17

您的状态栏已着色,因此导航抽屉在其后面不可见。请将状态栏设为透明,它就会出现。

http://blog.raffaeu.com/archive/2015/04/11/android-and-the-transparent-status-bar/

<!-- Make the status bar traslucent -->
<style name="AppTheme" parent="AppTheme.Base">
    <item name="android:windowTranslucentStatus">true</item> // add this item tag inside your Theme Styles.xml and Styles(v21).xml:
</style>

添加 windowTranslucentStatus 后没有任何变化。 - xyz rety
@xyz rety,你把它加在哪里了?你需要将它添加到正确的主题中,这个主题是你在清单文件中可以找到的应用程序主题,也可以在Styles(v21).xml中找到。不要复制整个块,只需获取标签并将其包含在你正在使用的正确主题中即可。 - Charuක
我只在Styles(v21).xml中添加了一个项目。 - xyz rety
我的应用程序的最低目标版本是15,所以我无法在styles.xml中添加windowTranslucentStatus,因此我只能将其添加到我的.Styles(v21).xml中。 - xyz rety
@xyz,那个方法对你有用吗?如果有用的话,你可以接受这个答案 ;) - Charuක
显示剩余2条评论

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接