Displaying a dialog with a button click in android

how can we display a dialog when a button is clicked in android?

+3
source share
2 answers

If you want to create Alert Dilaog in android when your button is touched, pls see this

findViewById(R.id.myButton).setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                               displayAlert();
                   retrun false;
}
}

 public  void displayAlert()
    {
     new AlertDialog.Builder(this).setMessage("Hi , I am Alert Dialog")  
           .setTitle("My Alert")  
           .setCancelable(true)  
           .setNeutralButton(android.R.string.ok,  
              new DialogInterface.OnClickListener() {  
              public void onClick(DialogInterface dialog, int whichButton){
                  finish();
              }  
              })  
           .show(); 
    }
+7
source

Try this in the android manifest. In any activity, you can create a dialog using theme.dialog in the android manifest.

 <activity android:name=".your_activity" android:theme="@android:style/Theme.Dialog" /> 

Hope this helps you all guys.

+1
source

Source: https://habr.com/ru/post/1794091/


All Articles