MainActivity.Java
package com.google.materialdesigntools;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void open(View v){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Your Title");
builder.setMessage("Your Message");
builder.setPositiveButton("Ok", null);
builder.show();
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#333333">
<Button
android:id="@+id/button"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:onClick="open"
android:text="Dialog"
android:textSize="20sp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
No comments:
Post a Comment