How to implement a custom AlertDialog View

前端 未结 11 894
悲&欢浪女
悲&欢浪女 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:31

    The simplest lines of code that works for me are are follows:

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(R.layout.layout_resource_id);
    builder.show();
    

    Whatever the type of layout(LinearLayout, FrameLayout, RelativeLayout) will work by setView and will just differ in the appearance and behavior.

提交回复
热议问题