How can I create my own theme for alertDialog? - android

I want to create a different theme for all of alertDialog instances. I need my own title view instead of the usual black title background. All text should have a blue color, and set the edge of the alertDialog to a round shape.
Is it possible to create our own theme for alert dialogs, using any style or creating a class which extends AlertDialog.Builder? I need a common theme or style for my all instances of alertDialog. I am using alertDialog in many places - one for singleChoice items, one with ArrayAdapter.
My alertDialog with array adapter:
String[] items = {"Edit profile","Change user","Change password","Logout"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(Loged.this,
R.layout.my_spinner_layout, items);
settingMenu.setAdapter(adapter, listener);
My alertDialog with single choice items:
alertDelete = new AlertDialog.Builder(getParent());
alertDelete.setTitle("Delete");
alertDelete.setCancelable(true);
CharSequence[] choice = {"this user","All user"};
alertDelete.setSingleChoiceItems(choice, 0,
For my all alertDialog, I need a common theme, like:

please check this link. here am creating my own alertDialog class
and its a simple method if you reuse the alertDialog in many situation in your application
how Create setAdapter() for a AlertDialog

I solved my problem by creating a class which extends Dialog, and I created my own functions. for example setMessage,setTitle,setPositiveButton,setNegativeButton etc.
But am confusing on how we can replace the setAdapter() and setSingleChoice().

Here one example For Dialog:
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Give a Title...");
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Put here any custom text!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_launcher);
Button dialogButton = (Button) dialog.findViewById(R.id.ButtonOK);
// if button is clickedthen dialog will closed
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
Custom AlertDialog
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext;
LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View urlayoutfile = inflater.inflate(R.layout.custom_dialog_xmlfile,(ViewGroup)findViewById(R.id.Yourlayout_id));
builder = new AlertDialog.Builder(this);
builder.setView(urlayoutfile);
alertDialog = builder.create();
alertDialog.show();

To use a specific style, use
ctw = new ContextThemeWrapper(this, R.style.MyStyle);
new AlertDialog.Builder(ctw)
.setTitle(...)

You can use layout as Different themes, styles, Backgrounds
customdialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
style="#android:style/Theme.Black.NoTitleBar.Fullscreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/layoutsample"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/dialoghdrbg"
android:orientation="horizontal" >
<ImageView
android:id="#+id/dialogheaderimage1"
android:layout_width="50dp"
android:layout_height="48dp"
android:scaleType="fitXY"
/>
<TextView
android:id="#+id/dialogheadertext1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:layout_marginLeft="1dp"
android:gravity="center_vertical|right"
android:textColor="#000000"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/dialogcontentbg"
android:orientation="vertical" android:gravity="center">
<TextView
android:id="#+id/dialogmessgetext1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#ffffff"
android:textSize="23dp"
android:text=""
android:gravity="center"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:gravity="center|center_horizontal"
android:layout_marginTop="20dip"
android:orientation="horizontal">
<Button
android:id="#+id/dialogokbutton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:background="#drawable/buttonanimation"
android:text="Retry"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="#+id/dialogcancelbutton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/buttonanimation"
android:text="Report"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
customDialog.java
final Dialog favDialog = new Dialog(Myclass.this,
android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
favDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
favDialog.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
favDialog.setContentView(R.layout.reloadurlpopuplayout);
favDialog.setCancelable(false);
ImageView dialogImage = (ImageView) favDialog
.findViewById(R.id.dialogheaderimage1);
dialogImage.setBackgroundResource(R.drawable.questionmark);
TextView dialogMesage = (TextView ) favDialog
.findViewById(R.id.dialogmessgetext1);
TextView dialogHeader = (TextView) favDialog
.findViewById(R.id.dialogheadertext1);
String descText = getString(R.string.RetryReportMessage);
dialogMesage.setBackgroundColor(0x00000000);
dialogMesage.setText(descText);
dialogHeader.setText(R.string.BrockenLinkHeader);
try {
favDialog.show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Related

Android Pop Up during opening of Application

I am developing an Android application, where I need to show a popup containing some message on application opening (Image attached for reference).
I have tried to achieve this using toast message and snack bar but could not do exact same.
Please suggest which component in Android to be used to achieve this functionality?
You can achieve the desired results using a dialog. I am sharing the code, you can modify it as you want but make sure you put it inside the onCreate method of the launcher activity.
This is the code for a simple dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Look at this dialog!")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//do things
}
});
AlertDialog alert = builder.create();
alert.show();
The one shown in the picture shared by you is a custom dialog where you have to make your own layout. Here is an example,
1. Create your own layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffffff">
<ImageView
android:layout_width="match_parent"
android:layout_height="120dp"
android:id="#+id/a"
android:gravity="center"
android:background="#DA5F6A"
android:src="#drawable/dialog_cross"
android:scaleType="fitCenter" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEXT"
android:id="#+id/text_dialog"
android:layout_below="#+id/a"
android:layout_marginTop="20dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="20dp"
android:textSize="18sp"
android:textColor="#ff000000"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="OK"
android:id="#+id/btn_dialog"
android:gravity="center_vertical|center_horizontal"
android:layout_below="#+id/text_dialog"
android:layout_marginBottom="20dp"
android:background="#drawable/btn_flat_red_selector"
android:layout_centerHorizontal="true"
android:textColor="#ffffffff" />
</RelativeLayout>
2. Create a class for the custom dialog
public class ViewDialog {
public void showDialog(Activity activity, String msg){
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.dialog);
TextView text = (TextView) dialog.findViewById(R.id.text_dialog);
text.setText(msg);
Button dialogButton = (Button) dialog.findViewById(R.id.btn_dialog);
dialogButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
3. Make an object in your launcher activity of the custom dialog class and call the function showDialog
ViewDialog alert = new ViewDialog();
alert.showDialog(getActivity(), "Thank you for installing the Paytm
App");
Or you could use an external library for getting the desired results
Pop.on(this).with().title(R.string.title).layout(R.layout.custom_pop).show();
where R.layout.custom_pop is the custom layout of your dialog.
Try this for same result:
dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right">
<Button
android:id="#+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="X" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Hello, this is your message"
android:textSize="20sp" />
</LinearLayout>
code:
private void showDialog() {
final Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.dialog);
Window window = dialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.BOTTOM;
wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);
dialog.findViewById(R.id.btnClose).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.cancel();
}
});
dialog.show();
}

Need transparent background like this [duplicate]

This question already has answers here:
Dialog with transparent background in Android
(25 answers)
Closed 6 years ago.
Need to make a layout like this.
Below is an alert box which has a transparent background containing spinner and a button below.
i ve tried this as far.
this is the layout file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#fff"
android:paddingBottom="50dp">
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/selectCity_xspn"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="6dp"
android:layout_marginTop="75dp" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/selectCity_xspn"
android:layout_alignParentStart="true"
android:layout_marginTop="70dp"
android:id="#+id/selectCtgry_xspn" />
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button2"
android:layout_marginTop="300dp"
android:layout_alignParentEnd="true" />
This is the java class where i ve used the transparent option at many places but it doesnt work.
accessing the function at the bottom in the following button.
customdialog_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
onCreateDialog2().show();
}
});
public Dialog onCreateDialog2() {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(Registeration.this);
View dialog_view = getLayoutInflater().inflate(R.layout.custom_dialog, null);
//dialog_view.setBackgroundResource(android.R.color.transparent);
builder.setView(dialog_view);
selectCity_spn=(Spinner)dialog_view.findViewById(R.id.selectCity_xspn);
selectCtgry_spn=(Spinner)dialog_view.findViewById(R.id.selectCtgry_xspn);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this.getBaseContext(), R.array.selectCity_spn, android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
assert selectCity_spn != null;
selectCity_spn.setAdapter(adapter);
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this.getBaseContext(), R.array.selectCtgry_spn, android.R.layout.simple_spinner_dropdown_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
assert selectCtgry_spn != null;
selectCtgry_spn.setAdapter(adapter2);
View v = getWindow().getDecorView();
v.setBackgroundResource(android.R.color.transparent);
return builder.create();
}
This will do
Dialog dialog = builder.create();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
return dialog;
Try this:-
Dialog dialog1 = new Dialog(Main3Activity.this);
dialog1.setCancelable(true);
dialog1.setContentView(view1);
dialog1.show();
you can set background transparent of any layout or any view or any component by adding this code in XML
android:background="#android:color/transparent"

how to change the alertdialog box style in android

I am just trying to build a alertdialog for my android application.
what I actually want is a dialog box like this:
whose positive and negative button are filled across dialog box
but I always get something like this:
and these two buttons stick together at the right corner of dialog box
can anybody tell me what to do to change the alertdialog from the second one to first one?
many thanks
For that You need to create custom dilogbox Like this
Dialog xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/image"
android:layout_width="50dp"
android:layout_height="50dp"
android:contentDescription="#drawable/ic_launcher"
android:src="#drawable/ic_launcher" />
<Button
android:id="#+id/button"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_below="#+id/image"
android:layout_centerHorizontal="true"
android:text="Dismiss" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_above="#+id/button"
android:layout_toRightOf="#+id/image"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
And In your Activity :
final Dialog dialog = new Dialog(MainActivity.this);
//setting custom layout to dialog
dialog.setContentView(R.layout.cusotm_dialog_layout);
dialog.setTitle("Custom Dialog");
//adding text dynamically
TextView txt = (TextView) dialog.findViewById(R.id.textView);
txt.setText("Put your dialog text here.");
ImageView image = (ImageView)dialog.findViewById(R.id.image);
image.setImageDrawable(getResources().getDrawable(android.R.drawable.ic_dialog_info));
//adding button click event
Button dismissButton = (Button) dialog.findViewById(R.id.button);
dismissButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
You can set customized layout to alert dialog by using setView(view) method like this:
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.alert_layout, null);
dialogBuilder.setView(dialogView);
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();

Android Custom AlertDialog not drawn correctly

I'm trying to customise the appearance of an AlertDialog. The problem is that I don't know how to get rid of the black lines that appear above my first TextView and EditText at the bottom (above the grey button regions).
Here is is my XML. What am I missing?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#color/butGreyBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="30"
android:text=""
android:background="#00000000"
android:textColor="#android:color/white"
android:textSize="22sp"
android:layout_margin="0dp"
android:gravity="center" />
<TextView
android:id="#+id/tv_prompt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="30"
android:text=""
android:background="#00000000"
android:textColor="#android:color/white"
android:textSize="18sp"
android:layout_margin="0dp"
android:gravity="center" />
<EditText
android:id="#+id/edit_text"
android:inputType="textCapSentences|textAutoCorrect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"/>
</LinearLayout>
Here's the code too - which is probably where the problem lies:
View alertView;
AlertDialog.Builder builder = new AlertDialog.Builder( mContext );
LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
alertView = inflater.inflate(R.layout.alert_dialog_text, null);
builder.setView( alertView );
AlertDialog alertDialog = builder.create();
alertDialog.setView( alertView, 0,0,0,0 );
final EditText input = (EditText) alertView.findViewById( R.id.edit_text );
TextView tvTitle = (TextView) alertView.findViewById( R.id.tv_title );
TextView tvPrompt = (TextView) alertView.findViewById( R.id.tv_prompt );
tvTitle.setText( "Rename Playlist" );
tvPrompt.setText( "Enter new Playlist name." );
// Set up the buttons
builder.setPositiveButton( "OK", new DialogInterface.OnClickListener()
{
#Override
public void onClick( DialogInterface dialog, int which )
{
mNewName = input.getText().toString();
}
} );
builder.setNegativeButton( "Cancel", new DialogInterface.OnClickListener()
{
#Override
public void onClick( DialogInterface dialog, int which )
{
mNewName = "";
dialog.cancel();
}
} );
builder.show();
#sparky...
1) xml in Values Folder and add this code
wrap_content
wrap_content
#color/transparent1
false
true
and make a reference this Theme to Your Dialog Like this
Dialog dialog = new Dialog(activity, R.style.CustomDialogTheme);
then set Your custom Dialog Layout Xml file as setContentView.
dialog.setContentView(R.layout.customdialog);
2)you are not closing the parent LinearLayout at the end
and you are using #000000 color code for parent layout this will display black color at background
try to change the color code you bottom color will chance. and use
requestWindowFeature(Window.FEATURE_NO_TITLE);
in you dialog class this will remove the dialog title so your top color also will remove..
Let me know if you need any help
Thanks
I fixed this in the end by implementing my own custom dialog instead of using the AlertDialog.

Using drawables instead of text for AlertDialog Buttons

I'm trying to set the Positive, Negative and Neutral buttons of an AlertDialog to drawables rather than text.
I've been successful thus far using this:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setPositiveButton("Save", new DialogInterface.OnClickListener() {...})
.setNeutralButton("Trash", new DialogInterface.OnClickListener() {...})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {...});
AlertDialog alert = builder.create();
alert.show();
Button button0 = alert.getButton(AlertDialog.BUTTON_POSITIVE);
button0.setCompoundDrawablesWithIntrinsicBounds(this.getResources().getDrawable(R.drawable.ic_menu_save), null, null, null);
button0.setText("");
Button button1 = alert.getButton(AlertDialog.BUTTON_NEUTRAL);
button1.setCompoundDrawablesWithIntrinsicBounds(this.getResources().getDrawable(R.drawable.ic_menu_delete), null, null, null);
button1.setText("");
Button button2 = alert.getButton(AlertDialog.BUTTON_NEGATIVE);
button2.setCompoundDrawablesWithIntrinsicBounds(this.getResources().getDrawable(R.drawable.ic_menu_close_clear_cancel), null, null, null);
button2.setText("");
This is a workaround though, because I'm really just erasing the text after the fact. My problem is that you can't seem to instantiate a button without setting some kind of text.
Setting "[blank_space]" from the beginning yields the same result with the image being pushed to the left. Setting null or "" in the same place draws the AlertDialog without the button at all. You can see how it pushes to the left in the picture here:
Is there anyway to use pictures only? It would be much nicer than trying to handle translations for my simple situation.
AlertDialog is deprecated. Consider using DialogFragments instead. You'll have much more control and reuse ability. Here is a good google blog that demonstrated how to use it and customize it.
From android document,
setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom)
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.
Since you put your image on the left, therefore the image will display on the left of the button. You may try to place it at top/bottom.
The other way is to create your custom layout with 3 ImageButtons, and set it to the alert by
builder.setView(customLayout);
You have just to create your own custom dialog!! You can specify your ImageButton in a layout, then create a dialog with that layout, you don't need to go near the positive, negative and neutral buttons. You can find here a good tutorial just use ImageButton instead of Buttons in your custom layout.
Try this code:
LayoutInflater inflater=LayoutInflater.from(YourActivityName.this);
View view=inflater.inflate(R.layout.buttton, null);
AlertDialog.Builder builder=new AlertDialog.Builder(YourActivityName.this);
builder.setView(view);
builder.setTitle("Are you sure you want to exit?");
Button posButton=(Button) view.findViewById(R.id.pos);
Button neuButton=(Button) view.findViewById(R.id.neu);
Button negButton=(Button) view.findViewById(R.id.neg);
builder.create();
builder.show();
inflate buttton xml file as below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:id="#+id/pos"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"/>
<Button
android:id="#+id/neu"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"/>
<Button
android:id="#+id/neg"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"/>
</LinearLayout>
And at the end you can give click events to the individuals.Hope this will help you.
CustomDialog dialog = new Dialog(MyActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.login);
final EditText editTextEmailAddress = (EditText) dialog
.findViewById(R.id.editTextEmailAddress);
final EditText editTextPassword = (EditText) dialog
.findViewById(R.id.editTextPassword);
TextView txtViewForgetPswd = (TextView) dialog
.findViewById(R.id.txtViewForgetPswd);
txtViewForgetPswd.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// RETRIVE PASSWORD
dialog.dismiss();
}
});
ImageButton imgBtnSubmit = (ImageButton) dialog
.findViewById(R.id.imgBtnSubmit);
imgBtnSubmit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// CALL WEBSERVICE OR ASYNTASK TO LOG IN USER
String userName = editTextEmailAddress.getText()
.toString();
String password = editTextPassword.getText().toString();
if (userName.equals("") && password.equals("")) {
Toast.makeText(BibleActivity.this,
"Username or password cannot be empty.",
Toast.LENGTH_SHORT).show();
} else {
}
}
});
ImageButton imgBtnCancel = (ImageButton) dialog
.findViewById(R.id.imgBtnCancel);
imgBtnCancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// CLOSE DIALOG HERE FROM CROSS BUTTON
dialog.dismiss();
}
});
ImageButton btnCancelCross = (ImageButton) dialog
.findViewById(R.id.btnCancelCross);
btnCancelCross.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// CLOSE DIALOG HERE FROM CROSS BUTTON
dialog.dismiss();
}
});
dialog.show();
////XML LAYOUT "login"///
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="480dp"
android:background="#drawable/mbc_login" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_alignParentTop="true" >
<ImageButton
android:id="#+id/btnCancelCross"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="20dp"
android:background="#drawable/cross" >
</ImageButton>
</FrameLayout>
<TextView
android:id="#+id/txtViewEmailLbl"
android:layout_width="200dp"
android:layout_height="20dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="Email address"
android:textColor="#000000" >
</TextView>
<EditText
android:id="#+id/editTextEmailAddress"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_below="#+id/txtViewEmailLbl"
android:layout_centerHorizontal="true"
android:hint="example#eg.com"
android:imeOptions="actionNext" >
</EditText>
<TextView
android:id="#+id/txtViewPswdLbl"
android:layout_width="200dp"
android:layout_height="20dp"
android:layout_below="#+id/editTextEmailAddress"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Password"
android:textColor="#000000" >
</TextView>
<EditText
android:id="#+id/editTextPassword"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_below="#+id/txtViewPswdLbl"
android:layout_centerHorizontal="true"
android:hint="password123"
android:imeOptions="actionNext"
android:inputType="textPassword" >
</EditText>
<TableRow
android:id="#+id/tblRowSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editTextPassword"
android:layout_centerHorizontal="true"
android:layout_margin="10dp" >
<ImageButton
android:id="#+id/imgBtnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/btn_submit" >
</ImageButton>
<ImageButton
android:id="#+id/imgBtnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/btn_cancel" >
</ImageButton>
</TableRow>
<TextView
android:id="#+id/txtViewForgetPswd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tblRowSubmit"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:text=" Forget Password ? "
android:textColor="#306EFF"
android:textStyle="italic" >
</TextView>
</RelativeLayout>

Categories

Resources