我有一个用于dialog_volume_all.xml
的XML的Android绑定,该XML是一种布局。因此,其绑定称为DialogVolumeAllBinding
。我像这样膨胀它:
DialogVolumeAllBinding dialogVolumeAllBinding = DialogVolumeAllBinding.inflate(LayoutInflater.from(MainActivity.this));
并且我正在通过它创建一个对话框
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.MyDialogTheme);
AlertDialog alert = builder.create();
alert.setView(dialogVolumeAllBinding);
但是我也想在对话框中实现public boolean onTouchEvent(MotionEvent event) {
。
如何从绑定中实现对话框上的内容?
在将视图设置为对话框之前,创建一个变量视图,并使用dialogVolumeAllBinding.root对其进行初始化,这将返回根视图。
View root = dialogVolumeAllBinding.root;
现在您可以在此根视图上实现onTouchListener或任何其他接口。
root.setOnTouchListener(new OnTouchListener(){
// your code
});