我最初的目标是模态对话框,但你知道,Android 不支持这种类型的对话框.或者,构建一个以对话为主题的活动可能会起作用.
这是代码,
My original goal here was a modal dialog, but you know, Android didn't support this type of dialog. Alternatively, building a dialog-themed activity would possibly work.
Here's code,
public class DialogActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(android.R.style.Theme_Dialog);
super.onCreate(savedInstanceState);
requestWindowFeature (Window.FEATURE_NO_TITLE);
Button yesBtn = new Button(this);
yesBtn.setText("Yes");
yesBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
DialogActivity.this.finish();
}
});
this.setContentView(yesBtn);
}
但是,背景总是黑色的,这真的很混乱.人们遇到了同样的问题,
http://code.google.com/p/android/issues/detail?id=4394
我只是想让它看起来更像用户的对话.那么,如何让这个 DialogActivity 透明且不覆盖底层屏幕呢?
谢谢.
However, the background was always black, that really confusing. People got same problem,
http://code.google.com/p/android/issues/detail?id=4394
I just wanna make it look more dialog-like for user. So, how to get this DialogActivity transparent and never cover underlying screen?
Thanks.
这就是我创建样式的方式
This was how I created the style
<style name="CustomDialogTheme" parent="android:Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
</style>
这样就可以创建一个透明的对话框了.
You can create a tranparent dialog by this.
public class DialogActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(" ");
alertDialog.setMessage("");
alertDialog.setIcon(R.drawable.icon);
alertDialog.setButton("Accept", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.setButton2("Deny", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}
}
在此之后,只需在 AndroidManifest.xml 中添加一行,您可以在其中定义清单中的活动.
After this just put a line in AndroidManifest.xml, where you define your activity in manifest.
android:theme="@android:style/Theme.Translucent.NoTitleBar"
这篇关于Android:如何创建一个透明的以对话框为主题的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!