Android:如何创建透明的对话主题活动 [英] Android: how to create a transparent dialog-themed activity

查看:136
本文介绍了Android:如何创建透明的对话主题活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的原始目标是一个模态对话框,但您知道,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.

这是我如何创建风格

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


推荐答案

您可以通过这个创建一个tranparent对话框。 p>

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:如何创建透明的对话主题活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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