Question

Okay, I asked another question here trying to make my activities look like dialogs. I'm thinking maybe instead of asking about a specific method, I should ask about what I'd like to do, and perhaps there is a different way to go about it...

Here's what I have. My app allows shortcuts to be placed on the home screen. The code and logic for creating the shortcuts all works flawlessly, and the shortcuts then launch the proper activity which shows what it's supposed to... again, all works flawlessly.

What I'm wondering though, is is there a way to have the home screen shortcut launch my activity as a dialog (as opposed to simply trying to make my activity LOOK like a dialog)?

Was it helpful?

Solution

Add this in your manifest, in the activity you want to look like dialog, declaration:

<activity android:theme="@android:style/Theme.Dialog">

for more information and themes: http://developer.android.com/guide/topics/ui/themes.html

furthermore, to this proggramatically you can use the following code:

public class ShowDialogActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    //
    //Log.d("DEBUG", "showing dialog!");

    Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.select_dialog_singlechoice);
    dialog.setTitle("Your Widget Name");
    dialog.setCancelable(true);
    dialog.setCanceledOnTouchOutside(true);
    TextView text = (TextView) dialog.findViewById(R.id.text1);
    text.setText("Message");

    dialog.show();
    //
   dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

    public void onCancel(DialogInterface arg0) {
        finish();
    }

   });
}

}

You can choose whatever layout you wish for the dialog and design it as you want.

In addition you would need to set this activity declaration in the manifest for the following:

<activity android:name=".ShowDialogActivity"
          android:theme="@android:style/Theme.Translucent.NoTitleBar">
</activity>

Hope this is what you was looking for, Gal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top