将immersive mode
与viewPager
视图一起使用时 - > fullscreen_content
未调整为全屏。
但是在Android工作室提供的模板中使用相同的代码它可以正常工作。
我最好的猜测是它与android:fitsSystemWindows="true"
有关。
如果您看到下面的屏幕截图,则绿色是使用android:fitsSystemWindows="true"
的视图的背景,并且浅色用作整个活动的背景以进行调试。
解决方案是什么?还有其他方法吗?
实施沉浸式的XML活动
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".Camera.CameraActivity">
<FrameLayout
android:fitsSystemWindows="true"
android:background="@color/colorAccent"
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Camera.CameraActivity">
<com.brotherpowers.audiojournal.View.AJViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/viewpager_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:padding="@dimen/spacing.8"
app:fillColor="@color/viewpager_active"
app:pageColor="@color/viewpager_inactive"
app:strokeColor="@android:color/transparent"/>
</RelativeLayout>
</FrameLayout>
JAVA活动显示/隐藏全屏
private final Handler uiHandler = new Handler();
private boolean fullScreen;
private void hide() {
// Hide UI first
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
fullScreen = true;
// Schedule a runnable to remove the status and navigation bar after a delay
uiHandler.removeCallbacks(showRunnable);
uiHandler.postDelayed(hideRunnable, 100);
}
private void show() {
// Show the system bar
_contentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
fullScreen = false;
// Schedule a runnable to display UI elements after a delay
uiHandler.removeCallbacks(hideRunnable);
uiHandler.postDelayed(showRunnable, 100);
}
private final Runnable showRunnable = () -> {
// Delayed display of UI elements
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.show();
}
_contentView.requestLayout();
};
private final Runnable hideRunnable = () -> {
// removal of status and navigation bar
_contentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
_contentView.requestLayout();
};
答案 0 :(得分:-1)
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
SystemUiHelper uiHelper = new SystemUiHelper(this, SystemUiHelper.LEVEL_IMMERSIVE ,flags);
uiHelper.hide();
}