简体   繁体   中英

Pop up in android application

I want to display a popup like screen when I click on version icon in the menuitem . kindly explain how can I achieve this ?

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();

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.

/**
     * 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;
    }

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM