[英]How to remove white space or color around AlertDialog
I have created a layout, Inflated it and then assigned it to an AlertDialog. 我创建了一个布局,对其进行了膨胀,然后将其分配给AlertDialog。 Everything is fine but I can't figure out why white spaces are showing around my AlertDialog.
一切都很好,但我无法弄清楚为什么我的AlertDialog周围会出现空白区域。
Layout Code: 布局代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:background="@drawable/dialog_backgrounds">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Player Name"
android:id="@+id/tvPlayerName"
android:textSize="24sp"
android:textIsSelectable="false"
android:textColor="#FFFFFF"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text=""
android:ems="10"
android:id="@+id/etPlayerName"
android:gravity="center"
android:textSize="24sp"
android:textColor="#FFFFFF"
android:background="@drawable/hintborder"
android:padding="4dp"
android:maxLength="5"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Android Java Code: Android Java代码:
View nameDialogView = View.inflate(MainActivity.this, R.layout.player_name_dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
final AlertDialog dialog = builder.create();
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.setView(nameDialogView);
dialog.show();
Background image is in png and nine-patch 背景图片是png和九补丁
Result i am getting: 结果我得到:
Please guide me what is wrong here or any limitations. 请指导我这里有什么问题或任何限制。 Thanks.
谢谢。
I changed AlertDialog to Simple Dialog and added few lines that solved problem. 我将AlertDialog更改为简单对话框并添加了几行解决问题。
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(nameDialogView);
dialog.show();
dialog.getWindow().getDecorView().setBackgroundResource(android.R.color.transparent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.