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

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

问题描述

在这里我最初的目标是一个模式对话框,但你知道,安卓不支持这种类型的对话框。或者,构建一个对话主题的活动将可能工作。
下面是code,

 公共类DialogActivity延伸活动{

@覆盖
保护无效的onCreate(包savedInstanceState){

    setTheme(android.R.style.Theme_Dialog);

    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    按钮yesBtn =新的按钮(这一点);
    yesBtn.setText(是);
    yesBtn.setOnClickListener(新OnClickListener(){

        @覆盖
        公共无效的onClick(视图v){
            // TODO自动生成方法存根
            DialogActivity.this.finish();

        }

    });

    this.setContentView(yesBtn);
}
 

不过,背景总是黑色的,真正令人困惑。人们得到了同样的问题,
<一href="http://$c$c.google.com/p/android/issues/detail?id=4394">http://$c$c.google.com/p/android/issues/detail?id=4394
我只是想使它看起来更加对话式的用户。那么,如何得到这个DialogActivity透明,从不掩盖潜在的屏幕?
谢谢你。

这是我如何创建样式

 &LT;样式名称=CustomDialogTheme父=机器人:Theme.Dialog&GT;
    &LT;项目名称=机器人:windowBackground&GT; @android:彩色/透明&LT; /项目&GT;
    &LT;项目名称=机器人:windowNoTitle&GT;真&LT; /项目&GT;
    &LT;项目名称=机器人:windowFullscreen&GT;假&LT; /项目&GT;
&LT; /风格&GT;
 

解决方案

您可以通过此建立一个tranparent对话框。

 公共类DialogActivity延伸活动{
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        最后AlertDialog alertDialog =新AlertDialog.Builder(本).create();
        alertDialog.setTitle();
        alertDialog.setMessage();
        alertDialog.setIcon(R.drawable.icon);
        alertDialog.setButton(接受,新DialogInterface.OnClickListener(){
            公共无效的onClick(DialogInterface对话,诠释它){
            }
        });
        alertDialog.setButton2(拒​​绝,新DialogInterface.OnClickListener(){
            公共无效的onClick(DialogInterface对话,诠释它){
            }
        });
        alertDialog.show();
    }
}
 

在此只是把线在AndroidManifest.xml中,在这里您可以定义体现您的活动。

 安卓主题=@安卓风格/ Theme.Translucent.NoTitleBar
 

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

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

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天全站免登陆