17

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Matroska
  • 6,885
  • 14
  • 63
  • 99

3 Answers3

22

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 ?

Hubert
  • 16,012
  • 18
  • 45
  • 51
  • 5
    It works. I have set up an activity with android:theme="@android:style/Theme.Translucent.NoTitleBar" and then used the simple code to create a list dialog keeping attention to finish the activity on dialog cancel/click. – Matroska Mar 07 '10 at 19:04
3

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!

Nick
  • 3,504
  • 2
  • 39
  • 78
  • The problem is how to call it when a widget is pressed. It should be inside an activity...and an activity must always display something right? – Matroska Mar 07 '10 at 18:19
  • Oh, sorry, I misunderstood you then. Try setting the activity's theme to `android:theme="@android:style/Theme.Translucent.NoTitleBar"` – Nick Mar 07 '10 at 18:39
0

There is actually a far simpler way to do this than what I suggested below.
Have a look at: https://developer.android.com/guide/topics/ui/dialogs.html under the headline "Adding a list".

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Nick
  • 3,504
  • 2
  • 39
  • 78