How to create custom alert dialog in android?

前端 未结 9 1215
再見小時候
再見小時候 2020-12-09 10:36

I am developing a sample app.I am able to show alert on button click having some tittle and button .But now I want to show a pop up window having username (Label)

9条回答
  •  眼角桃花
    2020-12-09 11:06

    you can use Dialog , like this code :

    final Dialog dialog = new Dialog(context);
    // dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.custom);
    dialog.setTitle("Title...");
    
    // set the custom dialog components - text, image and button
    TextView text = (TextView) dialog.findViewById(R.id.text);
    text.setText("Android custom dialog example!");
    Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
    // if button is clicked, close the custom dialog
    dialogButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
    dialog.dismiss();
    }
    });
    dialog.show();
    

    if you want to remove title bar just use this code after define :

    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    

提交回复
热议问题