MainActivity.java
package com.sattar.aleartmessage;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
                public
void showAlart() {
                                ContextThemeWrapper
wrapper = new ContextThemeWrapper(this,
                                                                android.R.style.Holo_Light_ButtonBar);
                                AlertDialog.Builder
builder = new AlertDialog.Builder(wrapper);
                                builder.setIcon(R.drawable.ic_launcher);
                                builder.setTitle("Are
You There!!");
                                final
EditText editText = new EditText(this);
                                editText.setHint("Please
Enter Your Name!!");
                                editText.setHintTextColor(Color.RED);
                                editText.setGravity(Gravity.CENTER);
                                setTitleColor(Color.RED);
                                builder.setView(editText);
                                builder.setMessage("Please
Enter Your Name!!!");
                                builder.setPositiveButton("OK",
null);
                                builder.setNegativeButton("Cancell",
                                                                new
DialogInterface.OnClickListener() {
                                                                                @Override
                                                                                public
void onClick(DialogInterface arg0, int arg1) {
                                                                                                //
TODO Auto-generated method stub
                                                                                }
                                                                });
                                builder.create().show();
                }
                //
public void showAlart() {
                //
                //
ContextThemeWrapper wrapper=new
                //
ContextThemeWrapper(this,R.style.AppBaseTheme);
                //
AlertDialog.Builder builder=new AlertDialog.Builder(wrapper);
                //
builder.setMessage("Stop Your Process");
                //
builder.setPositiveButton("OK", null);
                //
builder.setNegativeButton("NO", new DialogInterface.OnClickListener()
{
                //
                //
@Override
                //
public void onClick(DialogInterface dialog, int which) {
                // //
TODO Auto-generated method stub
                //
                // }
                // });
                //
                //
builder.create().show();
                //
                // }
                @Override
                protected
void onCreate(Bundle savedInstanceState) {
                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.activity_main);
                }
                public
void aleart(View view) {
                                showAlart();
                }
                @Override
                public
boolean onCreateOptionsMenu(Menu menu) {
                                //
Inflate the menu; this adds items to the action bar if it is present.
                                getMenuInflater().inflate(R.menu.main,
menu);
                                return
true;
                }
}
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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
   
<Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:onClick="aleart"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="180dp"
        android:text="Show Alert" />
</RelativeLayout>
 
No comments:
Post a Comment