How to implement a custom AlertDialog View

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

    android.R.id.custom was returning null for me. I managed to get this to work in case anybody comes across the same issue,

    AlertDialog.Builder builder = new AlertDialog.Builder(context)
                .setTitle("My title")
                .setMessage("Enter password");
    final FrameLayout frameView = new FrameLayout(context);
    builder.setView(frameView);
    
    final AlertDialog alertDialog = builder.create();
    LayoutInflater inflater = alertDialog.getLayoutInflater();
    View dialoglayout = inflater.inflate(R.layout.simple_password, frameView);
    alertDialog.show();
    

    For reference, R.layout.simple_password is :

    
    
    
    
    
    
    
    
    

提交回复
热议问题