How to create a Custom Dialog box in android?

后端 未结 22 2770
囚心锁ツ
囚心锁ツ 2020-11-21 07:06

I want to create a custom dialog box like below

\"enter

I have tried the foll

22条回答
  •  感动是毒
    2020-11-21 07:39

    It's a class for Alert Dialog so that u can call the class from any activity to reuse the code.

    public class MessageOkFragmentDialog extends DialogFragment {
    Typeface Lato;
    String message = " ";
    String title = " ";
    int messageID = 0;
    
    public MessageOkFragmentDialog(String message, String title) {
        this.message = message;
        this.title = title;
    }
    
    
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
    
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    
        LayoutInflater inflater = getActivity().getLayoutInflater();
    
        View convertview = inflater.inflate(R.layout.dialog_message_ok_box, null);
    
    
        Constants.overrideFonts(getActivity(), convertview);
        Lato = Typeface
                .createFromAsset(getActivity().getAssets(), "font/Lato-Regular.ttf");
    
    
        TextView textmessage = (TextView) convertview
                .findViewById(R.id.textView_dialog);
    
        TextView textview_dialog_title = (TextView) convertview.findViewById(R.id.textview_dialog_title);
    
        textmessage.setTypeface(Lato);
        textview_dialog_title.setTypeface(Lato);
    
    
    
        textmessage.setText(message);
        textview_dialog_title.setText(title);
    
    
    
        Button button_ok = (Button) convertview
                .findViewById(R.id.button_dialog);
        button_ok.setTypeface(Lato);
    
        builder.setView(convertview);
        button_ok.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                dismiss();
    
            }
        });
    
    
        return builder.create();
    
    }
    }
    

    Xml file for the same is:

        
    
    
        
    
            
    
                
    
    
            
    
            
    
            
    
            
    
            

提交回复
热议问题