How can can I add custom buttons into an AlertDialog's layout?

后端 未结 6 907
误落风尘
误落风尘 2020-12-09 08:48

I have AlertDialog with Positive and Negative buttons. In AlertDialog layout I have EditText and two Buttons (btnAdd1, btnAdd2). I want when user click at the Button btnAdd1

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 09:27

    According to this approach i am able to create the image button but if i want to dismiss or cancel dialog on Cancel button then what i have to do..

    public static void alertDialogShow(final Context context,
                final String resultMobile) {
    
            LayoutInflater li = LayoutInflater.from(context);
            View promptsView = li.inflate(R.layout.prompt,
                    null);
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    context, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            // set prompts.xml to alertdialog builder
            alertDialogBuilder.setView(promptsView);
            final EditText userInput = (EditText) promptsView
                    .findViewById(R.id.editTextDialogUserInput);
            userInput.setText(resultMobile);
            userInput.setEnabled(false);
    btnCancel.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
    
                }
            });
    

提交回复
热议问题