在关注谷歌开发者关于twa的页面并隐藏网址栏之后,我现在有一个没有url栏的工作twa。但状态栏仍然可见。
是否可以在twa中隐藏状态栏以获得全屏视图?
安卓清单.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>
风格.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>
试试这个来隐藏你的状态栏
<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);
}