我无法点击此对话框。我只想要它应该包含一个图像,并且必须是可点击的。我添加了图像,但我无法点击它。
Dialog settingsDialog = new Dialog(this);
settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
settingsDialog.setContentView(getLayoutInflater().inflate(R.id.iv, null));
settingsDialog.show();
请帮忙!
答案 0 :(得分:0)
尝试:
View v = getLayoutInflater().inflate(R.id.iv, null);
ImageView im = (ImageView) v.findViewById(R.id.<your image view ID>);
settingsDialog.setContentView(v);
im.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
答案 1 :(得分:0)
如果您不想通过自定义警报对话框执行此操作,请使用此代码
AlertDialog.Builder建设者;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog);
builder = new AlertDialog.Builder(this);
//builder.setMessage("Do you want to Exit Scramble?")
builder.setCancelable(false)
.setIcon(R.drawable.sly)
.setTitle(" ")
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int id) {
finish();
}
});
builder.show();
}
假如你不想拥有OK按钮,你肯定需要去自定义Alert对话框。它非常简单。请参阅此网站:http://www.mkyong.com/android/android-custom-dialog-example/