我是 Android 新手,在获取与对话框关联的 View 时遇到问题。如果我创建一个这样的对话框:
AlertDialog.Builder adbuilder = new AlertDialog.Builder(Context);
adbuilder.SetTitle("Hello!");
adbuilder.SetNegativeButton("No", clickedNo);
adbuilder.SetPositiveButton("Yes", clickedYes);
AlertDialog ad = adbuilder.Create();
ad.Show();
我的问题是,这个对话框是否可以通过任何方式访问?我想在上面使用 findviewbyID,这甚至会分配一个 ID 吗?我知道您可以向它添加资源 ID 等,但我想看看是否有解决方法。我正在尝试获取该对话框的 View 。有 GetIdentifier
方法,但它对我不起作用。
最佳答案
我不确定您是否可以访问 AlertDialog Negative/PositiveButton,但您可以像这样使用 AlertDialog 内容区域
AlertDialog.Builder adbuilder = new AlertDialog.Builder(Context);
adbuilder.SetTitle("Hello!");
adbuilder.SetNegativeButton("No", clickedNo);
adbuilder.SetPositiveButton("Yes", clickedYes);
View v = ((LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.rz_promo_dialog, null);
v.findViewById(R.id.rz_dlg_img).setOnClickListener(...);
alert.setView(v);
AlertDialog ad = adbuilder.Create();
ad.Show();
[更新] 抱歉,我刚刚看到这是一个 c#/xamarin 问题。我的代码是 java 但在 c#/xamarin 中应该有类似的东西
关于c# - 如果没有为 AlertDialog 分配资源 ID,它是否会有资源 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31833268/