我试图在android生成一个自定义的对话框。我像下边这样创建我的对话框:
dialog = new Dialog(this);
dialog.setContentView(R.layout.my_dialog);
除了对话框的title,其他的都很好。就算我不设置对话框的title,当对话框弹出的时候仍然有一个空白的地方。
有什么方法可以隐藏掉这个空白的地方么?
我用 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);
如果我用这个代码,我会在最后一行得到一个空指针异常。对话框不是空的,所以我尝试查找的TextView不存在。
如果在我使用对话框的构造函数部分取消注释的部分,一切都很好,除了我的对话框布局上的title部分。