相关疑难解决方法(0)

Android:如何创建没有标题的Dialog?

我正在尝试在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构造函数的部分,一切正常,但对于我的对话框布局上方的标题.

android dialog android-layout

263
推荐指数
11
解决办法
22万
查看次数

如何获得AlertDialog标题?

我试图获取消息,以下代码行有效:

TextView dialogMessage = (TextView)dialogObject.findViewById(android.R.id.message);
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用以下行获取标题时它返回 null

TextView dialogTitle = (TextView)dialogObject.findViewById(android.R.id.tittle);
Run Code Online (Sandbox Code Playgroud)

testing android dialog

15
推荐指数
1
解决办法
7721
查看次数

标签 统计

android ×2

dialog ×2

android-layout ×1

testing ×1