gpt4 book ai didi

android - 某些设备上的对话框未填满整个窗口

转载 作者:行者123 更新时间:2023-11-30 05:05:40 25 4
gpt4 key购买 nike

当我摆弄 Google I/O 2018 Android App 时,我注意到在我的设备(小米 Mi5,Android 7.0)上,他们的对话框使整个屏幕变暗,除了(白色)状态栏,如屏幕截图所示:

screen1

它不会出现在模拟器上(在 6.0、7.0、8.0 上测试过)。

我查看了 View 层次结构,我注意到 DecorView 的子级的顶部填充设置为 60,而在模拟器上它设置为 0。

screen2 - 此 FrameLayout 的边界

这是他们对对话框的实现: https://github.com/google/iosched/blob/master/mobile/src/main/java/com/google/samples/apps/iosched/widget/CustomDimDialog.kt

class CustomDimDialog(context: Context?) : AppCompatDialog(context, R.style.Theme_IOSched_Dialog) {

init {
supportRequestWindowFeature(Window.FEATURE_NO_TITLE)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window?.run {
// Spread the dialog as large as the screen.
clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
}
}

override fun setContentView(view: View?) {
if (view != null) {
super.setContentView(wrap(view))
}
}

private fun wrap(content: View): View {
val res = context.resources
val verticalMargin = res.getDimensionPixelSize(R.dimen.dialog_vertical_margin)
val horizontalMargin = res.getDimensionPixelSize(R.dimen.dialog_horizontal_margin)
return FrameLayout(context).apply {
addView(content, FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT
).apply {
setMargins(horizontalMargin, verticalMargin, horizontalMargin, verticalMargin)
gravity = Gravity.CENTER
})
val rect = Rect()
setOnTouchListener { _, event ->
when (event.action) {
// The FrameLayout is technically inside the dialog, but we treat it as outside.
MotionEvent.ACTION_DOWN -> {
content.getGlobalVisibleRect(rect)
if (!rect.contains(event.x.toInt(), event.y.toInt())) {
cancel()
true
} else {
false
}
}
else -> {
false
}
}
}
background = ColorDrawable(ResourcesCompat.getColor(res, R.color.scrim, context.theme))
}
}

有人知道怎么解决吗?

最佳答案

试试这个,它会为你工作

    WindowManager manager = (WindowManager) 
getActivity().getSystemService(Activity.WINDOW_SERVICE);
int width;
width = manager.getDefaultDisplay().getWidth();
pauseDialog.getWindow().setBackgroundDrawable(null);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(pauseDialog.getWindow().getAttributes());
lp.width = width;
lp.gravity = Gravity.CENTER;
pauseDialog.getWindow().setAttributes(lp);

关于android - 某些设备上的对话框未填满整个窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54641531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com