自定义AlertDialog国界 [英] Custom AlertDialog Borders

查看:179
本文介绍了自定义AlertDialog国界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个自定义对话框。它例如code是:

 最后AlertDialog对话框;保护AlertDialog createDialog(INT dialogId){
    AlertDialog.Builder建设者;
    建设者=新AlertDialog.Builder(父);
    AlertDialog fDialog = NULL;    开关(dialogId){
        案例Constants.cusDialogtId:
            建设者=新AlertDialog.Builder(父);
            builder.setTitle(标题);
            LayoutInflater吹气=(LayoutInflater)parent.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            查看查看= inflater.inflate(R.layout.customdialog,NULL);
            builder.setView(视图);
            fDialog = builder.create();
            打破;
    }
    对话框= fDialog;
    返回对话框;
}

问题是所示的对话框时,它具有本地对话框的一些顶部和底部边框也与我的自定义对话框中显示的灰色背景。
有没有一些方法来只显示我的自定义对话框视图... ???

我使用的XML是:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =FILL_PARENT
机器人:方向=垂直
机器人:背景=@绘制/ bgsmall>
< EditText上机器人:ID =@ + ID / redeemamount
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =10dip
机器人:layout_marginLeft =20dip
机器人:layout_marginRight =20dip
机器人:提示=输入金额
安卓的inputType =numberDecimal>
< /&的EditText GT;
<按钮机器人:ID =@ + ID / submitRedeemAmountButton
机器人:layout_width =FILL_PARENT
机器人:layout_height =40dip
机器人:文字=提交
机器人:文字颜色=#FFFFFF
机器人:文字样式=大胆
机器人:背景=@绘制/ buttoncorner
机器人:layout_marginTop =20dip
机器人:layout_marginLeft =20dip
机器人:layout_marginRight =20dip
机器人:layout_marginBottom =20dip>
< /按钮>
< / LinearLayout中>


解决方案

我不认为你可以使用删除边框 AlertDialog.Builder

你可以做的是创建一个扩展了 CustomDialog 对话框,并在<$ C的构造$ C> CustomDialog 你夸大你的 customdialog.xml

此外,你需要创建一个自定义风格为您的对话框,隐藏边界。下面是一个例子:

 &LT;花柱
      NAME =CustomStyle
      父=机器人:Theme.Dialog&GT;
      &LT;项目
          NAME =机器人:windowBackground&GT; @色/透明&LT; /项目&GT;
      &LT;项目
          NAME =机器人:windowContentOverlay&GT; @空&LT; /项目&GT;
    &LT; /风格&GT;

还定义了透明色:

 &LT;彩色
      NAME =透明&GT;#00000000 LT; /彩色&GT;

你会使用创建对话框:

  CustomDialog对话框=新CustomDialog(这一点,R.style.CustomStyle);

I am creating a custom dialog. Its example code is:

final AlertDialog dialog;

protected AlertDialog createDialog(int dialogId) {
    AlertDialog.Builder builder;
    builder = new AlertDialog.Builder(parent);
    AlertDialog fDialog = null;

    switch(dialogId) {
        case Constants.cusDialogtId:
            builder = new AlertDialog.Builder(parent);
            builder.setTitle("Title");
            LayoutInflater inflater = (LayoutInflater)parent.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.customdialog, null);
            builder.setView(view);
            fDialog = builder.create();
            break;
    }
    dialog = fDialog;
    return dialog;
}

The problem is that when the dialog is shown, it has a gray background of the native dialog whose some top and bottom border is also shown with my custom dialog. Is there some way to show only my custom dialog view...???

The XML I am using is:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="@drawable/bgsmall" >
<EditText android:id="@+id/redeemamount"
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:layout_marginTop="10dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:hint="Enter amount"
android:inputType="numberDecimal">
</EditText>             
<Button android:id="@+id/submitRedeemAmountButton"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:text="Submit"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:background="@drawable/buttoncorner"
android:layout_marginTop="20dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginBottom="20dip">
</Button>
</LinearLayout>

解决方案

I don't think you can remove the borders by using AlertDialog.Builder.

What you can do is create a CustomDialog class that extends Dialog and in the constructor of your CustomDialog you inflate your customdialog.xml.

Also you will need to create a custom style for your dialog, that hides the borders. Here is an example:

    <style
      name="CustomStyle"
      parent="android:Theme.Dialog">
      <item
          name="android:windowBackground">@color/transparent</item>
      <item
          name="android:windowContentOverlay">@null</item>
    </style>

Also define the transparent color:

   <color
      name="transparent">#00000000</color>

And you will create your dialog using :

    CustomDialog dialog=new CustomDialog(this,R.style.CustomStyle);

这篇关于自定义AlertDialog国界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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