当前位置:网站首页>[original] unable to use the code dialog height and width to solve the screen problem
[original] unable to use the code dialog height and width to solve the screen problem
2022-06-30 20:49:00 【lozn】
I forgot all about not taking notes , Because Baidu is an unreliable answer , So the explored things still can't send note numbers
public static <T extends ViewDataBinding> Pair<Dialog,T> getDialog(Context context, @LayoutRes int layout, Class<T> parent_, ViewGroup viewGroup) {
Dialog dialog = new Dialog(context);
Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
window.getDecorView().setPadding(0, 0, 0, 0);
lp.dimAmount = 0;//dimAmount stay 0.0f and 1.0f Between ,0.0f Not dark at all ,1.0f All dark
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
lp.gravity = Gravity.TOP;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().setBackgroundDrawable(null);
T dataBinding = DataBindingUtil.inflate(LayoutInflater.from(context),layout, viewGroup, false);
// dialog.getWindow().setBackgroundDrawableResource(android.R.color.white);
/*
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:backgroundDimEnabled">true</item>
*/
dialog.setContentView(dataBinding.getRoot());
dialog.setCanceledOnTouchOutside(true);
return new Pair<>(dialog,dataBinding);
}
Including modifying the color of the status bar
@SuppressLint("WrongConstant")
public static <T extends ViewDataBinding> Pair<Dialog,T> getDialog(Context context, @LayoutRes int layout, Class<T> parent_, ViewGroup viewGroup) {
Dialog dialog = new Dialog(context);
Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0 Fully transparent implementation
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(AppContext.getInstance().getResources().getColor(R.color.themeColor));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
// lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}
} else {//4.4 Fully transparent status bar
// window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);// No need for transparency
}
window.getDecorView().setPadding(0, window.getDecorView().getPaddingTop(), 0, 0);
lp.dimAmount = 0;//dimAmount stay 0.0f and 1.0f Between ,0.0f Not dark at all ,1.0f All dark
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
lp.gravity = Gravity.BOTTOM;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
T dataBinding = DataBindingUtil.inflate(LayoutInflater.from(context),layout, viewGroup, false);
dialog.setContentView(dataBinding.getRoot());
dialog.setCanceledOnTouchOutside(true);
return new Pair<>(dialog,dataBinding);
}
public static void setTranslucentStatus(Activity activity) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0 Fully transparent implementation
Window window = activity.getWindow();
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
} else {//4.4 Fully transparent status bar
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
Back pad There are some problems below 3 Three full screen dialog implementation methods
/**
*
* Set up View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR The status bar is white , The font is black pad Neither on bug, Automatically padding status bar SYSTEM_UI_FLAG_HIDE_NAVIGATION solve pad The navigation bar is transparent and invisible, and the layout extends to the status bar , But there is a problem that needs to be solved . The status bar changes to the specified color
* @param context
* @param layout
* @param parent_ Just to prevent the trouble of forced rotation
* @param viewGroup
* @param <T>
* @return
*/
@SuppressLint("WrongConstant")
public static <T extends ViewDataBinding> Pair<Dialog,T> getDialog(Context context, @LayoutRes int layout, Class<T> parent_, ViewGroup viewGroup) {
Dialog dialog = new Dialog(context);
Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
// If not highlighted Just remove window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0 Fully transparent implementation
window.getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);// View.SYSTEM_UI_FLAG_LAYOUT_STABLE|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);// Status bar color cannot be modified without setting , But it can solve pad The upper layout is deferred to the status bar problem
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS );// If you want to set column color customization, you must not set SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN If the status bar is not set, it will become transparent. The custom color setting is invalid [pad Verified ] window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);// If you want to set column color customization, you must not set ,SYSTEM_UI_FLAG_LAYOUT_STABLE not essential .
window.setStatusBarColor(AppContext.getInstance().getResources().getColor(R.color.themeColor));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
// lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}
//https://www.jianshu.com/p/50d2024fa60a
} else {//4.4 Fully transparent status bar
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);// No need for transparency
}
window.getDecorView().setPadding(0, 0, 0, 0);
lp.dimAmount = 0;//dimAmount stay 0.0f and 1.0f Between ,0.0f Not dark at all ,1.0f All dark
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
lp.gravity = Gravity.BOTTOM;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
T dataBinding = DataBindingUtil.inflate(LayoutInflater.from(context),layout, viewGroup, false);
dialog.setContentView(dataBinding.getRoot());
dialog.setCanceledOnTouchOutside(true);
return new Pair<>(dialog,dataBinding);
}
/**
* stay pad The layout is derived to the status bar , Need to be handled manually Fill the height of the status bar with your own piece of any color view.
* @param context
* @param layout
* @param parent_
* @param viewGroup
* @param <T>
* @return
*/
public static <T extends ViewDataBinding> Pair<Dialog,T> getFullDialog(Context context, @LayoutRes int layout, Class<T> parent_, ViewGroup viewGroup) {
// Full screen dialog https://blog.csdn.net/qijingwang/article/details/118368281
AppCompatDialog dialog = new AppCompatDialog(context, R.style.ThemeOverlay_AppCompat_Dialog);
dialog.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
T dataBinding = DataBindingUtil.inflate(LayoutInflater.from(context),layout, viewGroup, false);
dialog.setContentView(dataBinding.getRoot());
Window window = dialog.getWindow();
window.getDecorView().setFitsSystemWindows(true);
window.getDecorView().setPadding(0,0, 0, 0);// Do not set the white background , But it can't be covered .
WindowManager.LayoutParams lp = window.getAttributes();
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
lp.gravity = Gravity.BOTTOM;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
dialog.setCanceledOnTouchOutside(true);
modifyDialogStatusBar(dialog,AppContext.getInstance().getResources().getColor(R.color.themeColor));
// The modified parameter attribute must be set later , But although the full screen , But the color of the status bar has changed
return new Pair<>(dialog,dataBinding);
}
@SuppressLint("WrongConstant")
public static void modifyDialogStatusBar(Dialog dialog, @ColorInt int color){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0 Fully transparent implementation
Window window = dialog.getWindow();
// window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
//decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); Status bar baoniu If not SYSTEM_UI_FLAG_LAYOUT_STABLE Direct full screen . The status bar is covered
// Layout derived to navigation bar .SYSTEM_UI_FLAG_HIDE_NAVIGATION and SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(color);
// window.setStatusBarColor(color);
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
// lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;// This causes the status bar to turn white and not change to the default modified color , , The color set above is invalid ,
}
dialog.getWindow().setAttributes(lp);
} else {//4.4 Fully transparent status bar
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
/**
* This method has defects in full screen , It will easily slide down
* @param context
* @param layout
* @param parent_
* @param viewGroup
* @param <T>
* @return
*/
public static <T extends ViewDataBinding> Pair<Dialog,T> getBottomSheetFullDialog(Context context, @LayoutRes int layout, Class<T> parent_, ViewGroup viewGroup) {
BottomSheetDialog dialog = new BottomSheetDialog(context){
@Override
public void show() {
super.show();
View mContent = getWindow().getDecorView().findViewById(R.id.design_bottom_sheet);
ViewGroup.LayoutParams orginLayoutParams = mContent.getLayoutParams();
orginLayoutParams.height=ViewGroup.LayoutParams.MATCH_PARENT;
mContent.setLayoutParams(orginLayoutParams);
BottomSheetBehavior<View> from = BottomSheetBehavior.from(mContent);
from.setState(BottomSheetBehavior.STATE_EXPANDED);
}
};
Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
dialog.getWindow().setAttributes(lp);
T dataBinding = DataBindingUtil.inflate(LayoutInflater.from(context),layout, viewGroup, false);
dialog.setContentView(dataBinding.getRoot());
dialog.setCanceledOnTouchOutside(true);
return new Pair<>(dialog,dataBinding);
}
pad The status bar is filled in If it is toolbar, Then put toolbar Of padding Set more
int[] position=new int[2];
dialogPair.second.getRoot().getLocationOnScreen(position);
if (position[0] == 0) {
int statusBarHeight = AppUtils.getStatusBarHeight(getThis());
// FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
dialogPair.second.toolbar.setPadding(0,statusBarHeight,0,0);// Handle pad Layout fill to status bar problem
}
Or customize one view Go to the status bar This problem can only be solved in pad The custom status bar color will appear on
int[] position = new int[2];
dataBinding.getRoot().getLocationOnScreen(position);
if (position[0] == 0) {
int statusBarHeight = AppUtils.getStatusBarHeight(getThis());
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.topMargin = statusBarHeight;
View view = new View(dataBinding.getRoot().getContext());
view.setBackgroundColor(getThis().getResources().getColor(R.color.themeColor));
ViewGroup viewGroup = (ViewGroup) dataBinding.getRoot();
viewGroup.addView(view, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, AppUtils.getStatusBarHeight(getThis())));
dataBinding.nestedScrollView.setPadding(0,statusBarHeight,0,0);// Solve the direct to the top problem .
dataBinding.btnClose.setPadding(dataBinding.btnClose.getPaddingLeft(),dataBinding.btnClose.getPaddingTop()+statusBarHeight,dataBinding.btnClose.getPaddingRight(),dataBinding.btnClose.getPaddingBottom());
}
The above repair status bar code is in show Then use
The above code USES x y by 0 That's it getLocationOnScreen() The wrong time to get results in 0 problem .
dataBinding.getRoot().addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
int[] position = new int[2];
dataBinding.getRoot().getLocationOnScreen(position);
int statusBarHeight = position[1] == 0?AppUtils.getStatusBarHeight(getThis()):0;
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.topMargin = statusBarHeight;
View view = new View(dataBinding.getRoot().getContext());
view.setBackgroundColor(getThis().getResources().getColor(R.color.themeColor));
ViewGroup viewGroup = (ViewGroup) dataBinding.getRoot();
viewGroup.addView(view, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, AppUtils.getStatusBarHeight(getThis())));
dataBinding.nestedScrollView.setPadding(0, statusBarHeight, 0, 0);// Solve the direct to the top problem .
dataBinding.btnClose.setPadding(dataBinding.btnClose.getPaddingLeft(), dataBinding.btnClose.getPaddingTop() + statusBarHeight, dataBinding.btnClose.getPaddingRight(), dataBinding.btnClose.getPaddingBottom());
Log.w("XY", Arrays.toString(position));
}
});
边栏推荐
- B_QuRT_User_Guide(35)
- Lumiprobe染料 NHS 酯丨BDP FL NHS 酯研究
- A complete collection of vulnerability scanning tools. Mom doesn't have to worry that I won't find any more vulnerabilities
- Mistakes the project manager should not make
- Jerry's question about long press boot detection [chapter]
- 北京大学ACM Problems 1003:Hangover
- qiao-npms:搜索npm包
- 学习总结
- 软工UML画图
- Lumiprobe生物素亚磷酰胺(羟脯氨酸)说明书
猜你喜欢

Solve the problems of Devops landing in complex environment with various tools with full stack and full function solutions

在线教育项目用户登录和注册

哈夫曼树(一)基本概念与C语言实现

基于开源流批一体数据同步引擎ChunJun数据还原—DDL解析模块的实战分享

Basic components of STL

基于开源流批一体数据同步引擎ChunJun数据还原—DDL解析模块的实战分享

Document contains & conditional competition

断点续传和下载原理分析

uniapp-路由uni-simple-router

PHP require/include 区别
随机推荐
Is it safe to open an account for online stock trading!?
关于,奇安信检测代码漏洞,XSS系列解决
Lumiprobe 改性三磷酸盐丨生物素-11-UTP研究
C file pointer
Lumiprobe生物素亚磷酰胺(羟脯氨酸)说明书
On inline function
请问海量数据如何去取最大的K个
Study on PEGylation of lumiprobe and PEG linker - iodine-peg3-acid
微信小程序怎么实现圆心进度条
Basic components of STL
Go language identifier and package name specification
偏向锁/轻量锁/重级锁锁锁更健康,上锁解锁到底是怎么完成实现的
Lumiprobe cell biology - dia, instructions for lipophilic tracer
左值引用和右值引用
Amazon restricts LGBTQ related search and product sales in the United Arab Emirates
报错FileSystemException: /datas/nodes/0/indices/gtTXk-hnTgKhAcm-8n60Jw/1/index/.es_temp_file:结构需要清理
Encoding type of Perl conversion file
CentOS - enable / disable Oracle
B_QuRT_User_Guide(34)
Summary of personal work of 21 groups in the first week of summer training