Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Android Activity looks like dialog

I am trying to open a dialog on widget click. I have solved the problem skinning the activity started on click with android:theme="@android:style/Theme.Dialog". Unfortunately I cannot reach the same look of a dialog.

This is the outcome:

Dialog from widget

Instead, I would like to reach this result (except for the button, of course):

Desired dialog from widget

(the widget dialog you can see keeping the screen pushed)

As you can see there are some differences: the color of the list items, the color of the text and the list item separator. Is there a predefined theme/style to obtain the same look of a standard dialog? If not, what are the steps to follow to reach that result?

I have seen that the widget provided by FoxyRing has the behaviour I would like to have.

like image 972
Matroska Avatar asked Mar 06 '10 23:03

Matroska


People also ask

What is custom dialog in Android?

The custom dialog uses DIALOG to create custom alert in android studio. Dialog display a small window i.e a popup which draws the user attention over the activity before they continue moving forward. The dialog appears over the current window and display the content defined in it.

When a dialog is displayed on top of your activity what will happen?

when a dialog is shown or it's window comes visible on top of an existing activity, then it overrides partial the activity window so existing activity will move to partially invisible state and you will get call to onPause() from ActivityThread. but to be sure we also need to consider here a one think...

What is alert dialog in Android?

Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.

How do I show alert dialog in Kotlin?

To set the action on alert dialog call the setPositiveButton(), setNeutralButton() and setNegativeButton() methods for positive, neutral and negative action respectively. The show() method of AlertDialog. Builder is used to display the alert dialog.


2 Answers

Why not use a "traditional" Main Activity with a transparent background layout

and call a standard dialog from it ?

... well if I understood you correctly, that would make the trick in a very easy way, isn't it ?

like image 196
Hubert Avatar answered Sep 17 '22 15:09

Hubert


you could dynamically create the dialog like this:

        Context mContext = this;
        Dialog dialog = new Dialog(mContext);

        dialog.setContentView(R.layout.data_dialog);
        dialog.setTitle("Your title");

        AlertDialog.Builder builder;
        AlertDialog alertDialog;

        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.data_dialog,
                (ViewGroup) findViewById(R.id.AbsoluteLayout01));

        builder = new AlertDialog.Builder(mContext);
        builder.setView(layout);
        alertDialog = builder.create();
        alertDialog.show();

        final EditText txtUsername = (EditText) layout.findViewById(R.id.txtUsername);

        final AlertDialog thisDialog = alertDialog;

         Button btnSave = (Button) layout.findViewById(R.id.btnSave);
         btnSave.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {

                String strtxtUsername = txtUsername.getText().toString();

                //do something...

             }
         });                

To close the dialog, call thisDialog.dismiss();

The style looks like the regular Theme.Light.NoTitleBar with a ListView with an Icon and a Title-Text.

Hope that helps!

like image 28
Nick Avatar answered Sep 18 '22 15:09

Nick