在我的应用程序中,我在对话框中显示图像。如果用户按下按钮,对话框将出现并占据整个屏幕的 80%。背景将变暗,因为这是 Android 对话框的默认行为。
Dialog dialog = new Dialog(ActQuiz.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
//nothing;
}
});
int width = (int) (getResources().getDisplayMetrics().widthPixels * 0.80);
int height = (int) (getResources().getDisplayMetrics().heightPixels * 0.80);
dialog.getWindow().setLayout(width, height);
ImageView imageView = new ImageView(ActQuiz.this);
String uri = "@drawable/" + info.getInfopicture();
int imageResource = getResources().getIdentifier(uri, null, getPackageName());
Drawable myDrawable = ContextCompat.getDrawable(ActQuiz.this, imageResource);
imageView.setImageDrawable(myDrawable);
new PhotoViewAttacher(imageView);
dialog.addContentView(imageView, new RelativeLayout.LayoutParams(width, height));
dialog.show();
所以我想要实现的是禁用按钮的调光,该按钮在对话框后面可见。
这是可能的还是我只能移除整个背景的调光?
最佳答案
Is this possible or can I only remove the dimming for the whole background?
不可能指示 Dialog
使除某些 View 或某些区域之外的所有内容变暗。没有这样的 API 可以做到这一点。
您可以做的是提供自定义可绘制对象作为 Dialog
窗口的背景。该可绘制对象将被赋予一个 Rect
,其坐标为 Button
和一个屏幕的 Rect
。除了提供的矩形之外,它将在所有地方绘制暗淡的(基本上是半透明的黑色)。看起来像 xfermode SrcOut是应该应用的模式。
关于android - 对话框 : dim everything except some region,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45118427/