How to implement a custom AlertDialog View

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

    You can create your view directly from the Layout Inflater, you only need to use the name of your layout XML file and the ID of the layout in file.

    Your XML file should have an ID like this:

    
    
    

    And then you can set your layout on the builder with the following code:

    LayoutInflater inflater = getLayoutInflater();
    View dialoglayout = inflater.inflate(R.layout.dialog_layout, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(dialoglayout);
    builder.show();
    

提交回复
热议问题