How We Can Use Alert Dialog In Android Studio
Dialog
Alert
Android
Studio
- By Code solution
- Jan 20th, 2021
- 0 comments
- 0
First Create New Project.
- First Create activity_main.xml code :)
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/button" android:text="Click" android:onClick="Click"/>
- After That Create MainActivity.java Code :)
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void Click(View view) { AlertDialog.Builder builder=new AlertDialog.Builder(this); AlertDialog alertDialog=builder.create(); alertDialog.setTitle("My Dialog Box"); alertDialog.setMessage("My Data"); alertDialog.show(); } }
Output:)