問題描述
好的,我問了另一個問題這里 試圖讓我的活動看起來像對話框.我在想,也許與其問具體的方法,不如問我想做什么,也許有不同的方法可以去做……
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...
這就是我所擁有的.我的應用程序允許將快捷方式放置在主屏幕上.創(chuàng)建快捷方式的代碼和邏輯都完美無缺,然后快捷方式啟動適當?shù)幕顒樱@示它應該做什么......再次,一切都完美無缺.
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();
}
});
}
}
您可以為對話框選擇任何您想要的布局并根據(jù)需要進行設計.
You can choose whatever layout you wish for the dialog and design it as you want.
此外,您還需要在清單中為以下內(nèi)容設置此活動聲明:
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.
這篇關于如何讓主屏幕快捷方式啟動對話框?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!