I want to display a popup like screen when I click on version icon in the menuitem
.
kindly explain how can I achieve this ?
4 Answers
Hi what you can do is you can invoke an activity normally as generally the corresponding activity declaration in the AndroidManifest.xml file looks like as follows:
<activity
android:name="com.aexample.YoursActivity"
android:label="@string/activity_name" >
</activity>
However, there is small trick that can be done to make any activity take on a Dialog form. For example, if we change the activity declaration in the AndroidManifest.xml file to this:
<activity
android:name="com.aexample.YoursActivity"
android:theme="@android:style/Theme.Holo.Dialog"
android:label="@string/activity_name" >
</activity>
What this android:theme="@android:style/Theme.Holo.Dialog"
does is change the theme of an activity. It's still a complete activity, but it has taken on a dialog form.
also what you can do is you can work around AlertDialog, the following example shows you how to display an alert box in Android
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("Your Title");
// set dialog message
alertDialogBuilder
.setMessage("Click yes to exit!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
MainActivity.this.finish();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();

- 5,244
- 2
- 25
- 43
-
I want the popup in `menuitem` so is it possible to add theme and layout for it ? P.S : I want the `menuitem` in all the activities. – Sukan Apr 08 '14 at 04:23
-
on clicking menuitem you can invoke the dialog themed activity, it will not be a problem!! – Jitesh Upadhyay Apr 08 '14 at 05:17
I did something similar to this. I used dialog activity for that. What you have to do is use
parent="@android:style/Theme.Holo.Dialog
in the theme for that activity.

- 1
- 1

- 1,348
- 2
- 18
- 41
/**
* Method to get a dialog with title, message and one button
*
* @param context
* @param title
* @param message
* @param positiveText
* @return AlertDialog
*/
public static AlertDialog getAlertDialog(Context context, String title,
String message, String positiveText) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
/* builder. */
builder.setMessage(message)
.setTitle(title)
.setCancelable(true)
.setNegativeButton(positiveText,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialogBox = builder.create();
return alertDialogBox;
}

- 61
- 5
u can create custom dialog xml layout and call that xml layout in ur activity
dialog = new Dialog(activity.this);
dialog.setContentView(R.layout.yourcustomlayout);
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
textview= (TextView) dialog.findViewById(R.id.textview_id);
dialog.show();
try this

- 2,057
- 1
- 12
- 15