使用透明状态栏时,新活动的状态栏变为白色

时间:2019-04-26 14:55:11

标签: android android-activity android-statusbar

每次我从[]启动新活动时,新活动的状态栏都会变为白色。出于某种原因,此问题不会影响最初加载的活动style={[styles.albumContainer, [(this.state.selectedItems.indexOf(item)>-1)?styles.selectedItem:styles.unselectedItem]]}

我意识到在线程Status bar turns white and does not show content behind it上已经对这种行为进行了足够的讨论,但是建议的大多数解决方案都围绕禁用透明状态栏而告终,我找不到其他解决方案对我有用。

这是我的一项活动的布局:

// Snippet to get CorDapp version info
System.out.println(getServiceHub().getAppContext().getCordapp().getTargetPlatformVersion()

// Snippet to get Corda Node version info
getServiceHub().getMyInfo().getPlatformVersion()

属性MainActivity在这里似乎没有任何作用,因为我的活动布局的所有内容都已经适合系统窗口边界。只是状态栏的颜色是完全白色的。

我依靠我的透明状态栏,因此无法禁用它。还有其他方法可以防止所描述的行为吗?

1 个答案:

答案 0 :(得分:0)

我现在已经确定了两种实现所需行为的解决方案:

  1. 在活动的onCreate方法中修改窗口标志:
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

这将使状态栏变为灰色,以便再次显示系统图标。

  1. 修改活动根目录布局的背景颜色以匹配所需的状态栏颜色:
<?xml version="1.0" encoding="utf-8"?>

<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@+id/root_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:background="@color/colorPrimaryDark">

    <FrameLayout
        android:id="@+id/search_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

由于Phoenix Wang的友好评论,我能够找到最后的解决方案。