我正在尝试在Android中生成自定义对话框.我像这样创建我的Dialog:
dialog = new Dialog(this);
dialog.setContentView(R.layout.my_dialog);
Run Code Online (Sandbox Code Playgroud)
除了Dialog的标题之外,Everythings工作正常.即使我没有设置对话框的标题,对话框弹出窗口在对话框的位置也有一个空格.
有没有办法隐藏Dialog的这一部分?
我尝试使用AlertDialog,但似乎布局设置不正确:
LayoutInflater inflater =
(LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.map_dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(view);
// dialog = new Dialog(this);
// dialog.setContentView(R.layout.map_dialog);
dialog = builder.create();
((TextView) dialog.findViewById(R.id.nr)).setText(number);
Run Code Online (Sandbox Code Playgroud)
如果我使用这段代码,我会在最后一行得到一个空指针异常.该对话框不为null,因此我尝试检索的TextView不存在.
如果我取消注释我使用Dialog构造函数的部分,一切正常,但对于我的对话框布局上方的标题.