我想做什么:
创建自定义警告对话框。按钮就像任何警告对话框一样,但上面有两个TextEdit输入框。我不想创建一个自定义的对话框,而是一个定制的警告对话框。
这是我正在尝试的第三种方法:http://developer.android.com/guide/topics/ui/dialogs.html
它说:
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();
文档说明:
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
第一个参数是布局资源ID,第二个参数是根视图的ID。
问题是我不知道布局的根是什么? 我将在Activity中启动此对话框。 我应该使用活动的布局ID吗? layout_root是从哪里来的?
也尝试过:
View layout = inflater.inflate(R.layout.my_custom_layout,
(ViewGroup) findViewById(android.R.id.content).getRootView());
结果是空指针。