Dialog全屏显示状态栏 Dialog全屏设置修改状态栏颜色兼容刘海屏_qijingwang的博客-CSDN博客
Window dialogWindow = mDialog.getWindow();
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
if(Build.VERSION.SDK_INT >= 28)
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
dialogWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// View decorView = dialogWindow.getDecorView();
// int systemUiVisibility = decorView.getSystemUiVisibility();
// int flags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN;
// systemUiVisibility |= flags;
// dialogWindow.getDecorView().setSystemUiVisibility(systemUiVisibility);
//dialog全屏显示状态栏
dialogWindow.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
dialogWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
dialogWindow.setStatusBarColor(Color.TRANSPARENT);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
dialogWindow.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
lp.width = LinearLayout.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
lp.alpha = 1.0f; // 透明度
dialogWindow.setAttributes(lp);
====================================================
1. View.SYSTEM_UI_FLAG_VISIBLE:显示状态栏,Activity不全屏显示(恢复到有状态栏的正常情况)。
2. View.INVISIBLE:隐藏状态栏,同时Activity会伸展全屏显示。
3. View.SYSTEM_UI_FLAG_FULLSCREEN:Activity全屏显示,且状态栏被隐藏覆盖掉。
4. View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN:Activity全屏显示,但状态栏不会被隐藏覆盖,状态栏依然可见,Activity顶端布局部分会被状态遮住。
5. View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION:效果同View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
6. View.SYSTEM_UI_LAYOUT_FLAGS:效果同View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
7. View.SYSTEM_UI_FLAG_HIDE_NAVIGATION:隐藏虚拟按键(导航栏)。有些手机会用虚拟按键来代替物理按键。
8. View.SYSTEM_UI_FLAG_LOW_PROFILE:状态栏显示处于低能显示状态(low profile模式),状态栏上一些图标显示会被隐藏。
toast 修改背景
Toast toast= Toast.makeText(context, "", Toast.LENGTH_SHORT);
View view = toast.getView();
view.setBackgroundResource(R.drawable.img_dtfzrefresh);
toast.show();
shape动态改颜色
GradientDrawable drawable = (GradientDrawable) ContextCompat.getDrawable(context, R.drawable.shape_online_white_bg);
drawable.setColor(Color.RED);
llDialog.setBackground(drawable);
监听横竖屏切换
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(getApplicationContext(), "横屏", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "竖屏", Toast.LENGTH_SHORT).show();
}
}
处理lib包sdk版本与app不一致
<uses-sdk tools:overrideLibrary="android.support.v17.leanback,com.sfit.ctp.info"/>