【问题标题】:remove white space from the navigation bar android从导航栏android中删除空格
【发布时间】:2021-11-16 13:03:42
【问题描述】:

我正在尝试启用全屏模式,但问题是导航栏上有永久空白区域,根本不会隐藏。我需要删除那个空白。这是实现

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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"
    android:id="@+id/player_layout"
    >

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:elevation="0dp"
        >

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/black"
            />
           

    </com.google.android.material.appbar.AppBarLayout>


    <com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/exoplayer_video"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/black"
        app:controller_layout_id="@layout/custom_controller"
        app:resize_mode="fit"
        app:player_layout_id="@layout/exo_simple_player_view"
        app:use_controller="true"
        />

</RelativeLayout>

这是styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <item name="colorPrimary">@color/purple_700</item>
        <item name="colorPrimaryDark">@color/black</item>
        <item name="colorAccent">#F87A8D</item>
        <item name="windowActionModeOverlay">true</item>



        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:navigationBarColor">@android:color/transparent</item>
       
    </style>

任何建议都会对我有所帮助。谢谢

【问题讨论】:

  • 据我所知,您不能将透明设置为导航栏颜色。将它设置为其他一些不透明的颜色应该可以解决它。
  • 我试过了,但它不起作用,空白仍然存在。

标签: android navigationbar removing-whitespace


【解决方案1】:
Theme.MaterialComponents.Light.DarkActionBar

Theme.MaterialComponents.Light.NoActionBar

【讨论】:

    【解决方案2】:

    更改父主题

    Theme.MaterialComponents.Light.DarkActionBar
    

    Theme.MaterialComponents.Light.NoActionBar
    

    如果您只想全屏显示此活动,请在您的 AndroidManifest.xml 文件中执行以下操作:

    <activity
        android:name=".YourActivityName"
        android:theme="@style/AppTheme.NoActionBar" />
    

    并在您的styles.xml 中添加以下样式

    <style name="AppTheme.NoActionBar">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
        </style>
    

    【讨论】:

    • 感谢您的回答,但空白仍然存在。唯一的方法是从根布局中删除android:fitsSystemWindows="true",但随后它开始与状态栏重叠,这仍然不正确。
    • @user16566034 请从您的布局文件中删除&lt;com.google.android.material.appbar.AppBarLayout&gt;,也不需要在root 中使用android:fitsSystemWindows="true" 请删除它然后检查。