如何让主屏幕快捷方式启动对话框?

时间:2023-04-23
本文介绍了如何让主屏幕快捷方式启动对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

好的,我问了另一个问题这里 试图让我的活动看起来像对话框.我在想,也许与其问具体的方法,不如问我想做什么,也许有不同的方法可以去做……

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

推荐答案

将此添加到您的清单中,在您希望看起来像对话框的活动中,声明:

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

此外,您可以通过编程方式使用以下代码:

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.

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

上一篇:自定义对话框上的 Admob 广告 下一篇:onUserInteraction 在 DialogPreference 中不起作用

相关文章