How can I have a home screen shortcut launch a dialog?

前端 未结 1 799
青春惊慌失措
青春惊慌失措 2020-12-17 07:13

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\

相关标签:
1条回答
  • 2020-12-17 08:04

    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.

    0 讨论(0)
提交回复
热议问题