如何在主屏幕快捷方式启动对话? [英] How can I have a home screen shortcut launch a dialog?

查看:152
本文介绍了如何在主屏幕快捷方式启动对话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我在这里提出了另一个问题尝试使我的活动看起来像对话框。我想可能不是询问一个具体的方法,我应该问一下我想做什么,也许有一个不同的方式去...

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.

我想知道的是,有没有办法让主屏幕快捷方式启动我的活动作为对话(而不是只是试图使我的活动LOOK像一个对话)?

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

此外,以此方式,您可以使用以下代码:

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>

希望这是你正在寻找的,Gal。

Hope this is what you was looking for, Gal.

这篇关于如何在主屏幕快捷方式启动对话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆