怎样才可以有一个主屏幕快捷方式启动的对话?才可以、快捷方式、有一个、屏幕

2023-09-04 10:36:39 作者:回忆是含着泪的微笑

好吧,我问了另一个问题here试图让我的活动看起来像对话框。我可能想到的,而不是问一个具体方法,我应该问什么我想要做的,也许有一种不同的方式去了解它...

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...

下面是我有。我的应用程序的快捷方式可以被放置在主屏幕上。在code和逻辑创建快捷方式的所有作品完美,和快捷键然后启动适当的活动这显示了它应该......再次,一切完美的作品。

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)?

推荐答案

添加这在你的清单,在活动中,你想要的样子对话框,声明:

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

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

有关详细信息和主题: http://developer.android.com/guide/topics/ui/themes.html

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

此外,本proggramatically您可以使用下面的code:

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.