android - 设置 subview 以适应系统窗口

标签 android

我正在设置一个简单的 View ,它只包含一个空的 RelativeLayout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:clipToPadding="false"
    android:background="@color/red"/>

使用这个主题:

<style name="FullscreenTheme" parent="BaseTheme">
    <item name="android:textColorSecondary">@android:color/white</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:navigationBarColor">@android:color/transparent</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>

这在 onCreate 中:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

这会产生预期的效果:

enter image description here

但是,当我尝试添加一个 child 时,我无法让它做同样的事情。 XML 如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:clipToPadding="false"
    android:background="@color/red">

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/bit_teal"
        android:fitsSystemWindows="true"
        android:clipToPadding="false"/>

</RelativeLayout>

这是它的样子:

enter image description here

有什么想法吗?

最佳答案

RelativeLayout 中删除 android:fitsSystemWindows="true"。我认为两者不能同时符合系统观点,父总是优先于子(ren)

关于android - 设置 subview 以适应系统窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33573443/

相关文章:

Android缩放动画到指定尺寸

android - 将相册添加到 Android 照片库(在代码中)

Android Dev - 运行 top 命令输出到 TextView

android - 无法获取博览会推送 token

javascript - 如何检测在 Android 运行时使用的是哪个 javascript 引擎(v8 或 JSC)?

java - 为什么我的 TimerTask 会出现此错误?

java - java的cron库

android - Telegram Bot API 中的 "getFile"方法

android - 何时以及多久为 ActionBar 调用 onPrepareOptionsMenu() 方法?

android - Jetifier/AndroidX 在 aar 中转换字符串