所以这与我之前提到的问题有关.我试图使用指定的布局显示警报.我的布局是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
调用和显示警报对话框的代码是:
Context mContext = getApplicationContext();
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
// use a custom View defined in xml
View view = LayoutInflater.from(mContext).inflate(R.layout.sell_dialog, (ViewGroup) findViewById(R.id.layout_root));
builder.setView(view);
builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do whatever you want with the input
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我得到一个错误说:
未捕获的处理程序:线程主要由于未捕获的异常而退出android.view.WindowManager $ NadTokenException:无法添加窗口 - 令牌null不适用于应用程序
我已经浏览了android开发网站,无法弄明白.我想我只是错过了一些明显的东西,但修复不是跳出来的.如何显示此警报对话框?