退出沉浸式模式问题

时间:2018-05-07 12:09:35

标签: android xamarin

我编写了以下代码,以便为沉浸式模式输入活动。

decorView = Window.DecorView;
var uiOptions = (int)decorView.SystemUiVisibility;
var newUiOptions = (int)uiOptions;
newUiOptions |= (int)SystemUiFlags.LowProfile;
newUiOptions |= (int)SystemUiFlags.Fullscreen;
newUiOptions |= (int)SystemUiFlags.HideNavigation;
newUiOptions |= (int)SystemUiFlags.Immersive;  
newUiOptions |= (int)SystemUiFlags.ImmersiveSticky;
decorView.SystemUiVisibility = (StatusBarVisibility)newUiOptions;

这很完美,我得到了一个完美的沉浸式模式。

现在的问题是,当我使用以下代码退出沉浸式模式时,它会退出沉浸式模式,但会将状态栏和导航栏变为白色。

在沉浸式模式之前:

enter image description here

状态栏和导航很轻

退出沉浸式模式后

enter image description here

要退出沉浸式模式,我使用以下代码

decorView = Window.DecorView;
decorView.SystemUiVisibility = StatusBarVisibility.Visible;

我尝试过其他一些事情,例如以下

How to completely exit from Immersive full screen mode?

https://developer.android.com/training/system-ui/immersive

它们可以工作,但都带有白色状态栏和导航栏。

另外,是的,我使用的是LightStatusBarLightNavigationBar,但即使在退出沉浸式模式时设置不起作用,例如

decorView = Window.DecorView;
var uiOptions = (int)decorView.SystemUiVisibility;
var newUiOptions = (int)uiOptions;
newUiOptions |= (int)SystemUiFlags.LightNavigationBar;
newUiOptions |= (int)SystemUiFlags.LightStatusBar;
decorView.SystemUiVisibility = (StatusBarVisibility)newUiOptions;

我做的任何事情,退出沉浸式模式后我都无法让状态栏和导航栏恢复正常

对此有什么想法吗?

STYLES.XML

<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>

    <item name="android:windowNoTitle">true</item>    
    <item name="android:statusBarColor">#ffffff</item>    
    <item name="android:windowLightStatusBar">true</item>
    <item name="android:navigationBarColor">@color/colorPrimary</item>
    <item name="android:windowLightNavigationBar">true</item>
    <item name="android:actionBarStyle">@style/CustomActionBarStyle</item>
  </style>

  <style name="CustomActionBarStyle" parent="Theme.AppCompat.Light.NoActionBar">    
    <item name="android:titleTextStyle">@style/NoTitleText</item>
    <item name="android:subtitleTextStyle">@style/NoTitleText</item>
  </style>

  <style name="NoTitleText">
    <item name="android:textSize">0sp</item>
    <item name="android:textColor">#00000000</item>
  </style>

干杯

1 个答案:

答案 0 :(得分:1)

styles.xml文件中,更改此内容:

<item name="android:statusBarColor">#ffffff</item>

到此:

 <item name="android:statusBarColor">@color/colorPrimary</item>