在受信任的Web活动中隐藏StatusBar

时间:2019-04-13 05:33:10

标签: android android-statusbar android-fullscreen trusted-web-activity

遵循有关twa的Google Developers page并隐藏网址栏后,我现在有了一个没有网址栏的有效twa。但是StatusBar仍然可见。

是否可以在twa中隐藏StatusBar以获得全屏视图?

AndroidManifest.xml

<application
    android:allowBackup="true"
    android:icon="@mipmap/battlechoc_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:screenOrientation="landscape"
    android:theme="@style/Battlechoc.Fullscreen.Theme"
    tools:ignore="GoogleAppIndexingWarning">

    <meta-data
        android:name="asset_statements"
        android:value="@string/asset_statements" />

    <activity
        android:name="android.support.customtabs.trusted.LauncherActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:theme="@style/Battlechoc.Fullscreen.Theme">

        <meta-data
            android:name="android.support.customtabs.trusted.DEFAULT_URL"
            android:value="https://battlechoc.com" />

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE"/>
            <data
                android:scheme="https"
                android:host="@string/hostname"/>
        </intent-filter>
    </activity>
</application>

style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Battlechoc.Fullscreen.Theme" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

1 个答案:

答案 0 :(得分:0)

尝试此操作以隐藏状态栏

 <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/secondaryTextColor</item>

    <item name="android:windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

充分希望它将为您服务。

更新 好的,现在尝试一下。它将启用全屏模式,因此符合隐藏状态栏的要求。

    @Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        hideSystemUI();
    }
}

private void hideSystemUI() {
    // Enables regular immersive mode.
    // For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
    // Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE
            // Set the content to appear under the system bars so that the
            // content doesn't resize when the system bars hide and show.
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            // Hide the nav bar and status bar
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN);
}

// Shows the system bars by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}