Скрыть StatusBar в Trusted Web Activity

1

После перехода на страницу разработчиков Google о twa и скрытия панели URL у меня теперь есть рабочая twa без панели URL. Но StatusBar все еще виден.

Можно ли скрыть StatusBar в twa, чтобы получить полноэкранный вид?

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>

Теги:
android-statusbar
android-fullscreen
trusted-web-activity

1 ответ

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);
}
  • 0
    Я попробовал это, но это не работает для моего twa. Строка состояния и навигация по-прежнему видны
  • 0
    Спасибо за ваше обновление! Я собираюсь попробовать это снова :)
Показать ещё 2 комментария

Ещё вопросы

Сообщество Overcoder
Наверх
Меню