How to implement a custom AlertDialog View

前端 未结 11 981
悲&欢浪女
悲&欢浪女 2020-11-22 13:18

In the Android docs on AlertDialog, it gives the following instruction and example for setting a custom view in an AlertDialog:

If you want to display a
11条回答
  •  温柔的废话
    2020-11-22 13:41

    You are correct, it's because you didn't manually inflate it. It appears that you're trying to "extract" the "body" id from your Activity's layout, and that won't work.

    You probably want something like this:

    LayoutInflater inflater = getLayoutInflater();
    FrameLayout f1 = (FrameLayout)alert.findViewById(android.R.id.body);
    f1.addView(inflater.inflate(R.layout.dialog_view, f1, false));
    

提交回复
热议问题