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

eid*_*lon 1 android dialog shortcut homescreen

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

这就是我所拥有的.我的应用程序允许将快捷方式放在主屏幕上.用于创建快捷方式的代码和逻辑完美无瑕地工作,然后快捷方式启动适当的活动,显示它应该...再次,所有工作完美无瑕.

我想知道的是,有没有办法让主屏幕快捷方式启动我的活动作为对话框(而不是简单地尝试使我的活动像对话框一样)?

Gal*_*e33 12

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

<activity android:theme="@android:style/Theme.Dialog">
Run Code Online (Sandbox Code Playgroud)

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

此外,通过这个程序,您可以使用以下代码:

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();
    }

   });
}

}
Run Code Online (Sandbox Code Playgroud)

您可以选择对话框所需的任何布局,并根据需要进行设计.

此外,您需要在清单中为以下内容设置此活动声明:

<activity android:name=".ShowDialogActivity"
          android:theme="@android:style/Theme.Translucent.NoTitleBar">
</activity>
Run Code Online (Sandbox Code Playgroud)

希望这就是你想要的,Gal.