状态栏全屏适配
通过代码实现全屏:
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import androidx.fragment.app.FragmentActivity;
public class FullScreenUtil {
/**
* 全屏布局,不显示状态栏,适配刘海屏
*/
public static void fullScreen(FragmentActivity activity) {
Window window = activity.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
//允许window 的内容可以上移到刘海屏状态栏
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams lp = window.getAttributes();
lp.layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
window.setAttributes(lp);
}
}
}
通过设置主题theme实现全屏
默认values
<style name="PhotoTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:immersive">true</item>
<item name="android:windowFullscreen">true</item>
</style>
Android19, values-v19
<style name="PhotoTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:immersive">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
Android28, values-v28
<style name="PhotoTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:immersive">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
如果你看到了这里,觉得文章写得不错就给个赞呗?
更多Android进阶指南 可以扫码 解锁更多Android进阶资料
敲代码不易,关注一下吧。ღ( ´・ᴗ・` )