如何在对话框中打开时删除EditText
的默认矩形边框?
我尝试将背景设置为null,但它没有用。当我在对话框中使用时,只有EditText
出现矩形边框。
以下是 XML 布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background_whitedialog"
android:focusable="true"
android:focusableInTouchMode="true">
...
<android.support.design.widget.TextInputLayout
android:id="@+id/inputPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null" >
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="@dimen/dp48"
android:maxLines="1"
android:paddingLeft="@dimen/dp12"
android:textColor="@color/numbertextcolor"
android:textSize="@dimen/sp16" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
以下是 Java 代码:
Dialog dialog = new Dialog(mContext, R.style.DialogSlideAnim);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(R.layout.dialog_item);
dialog.show();
答案 0 :(得分:1)
要删除EditText中的边框,请在EditText中提供可绘制的背景。加上TextInputEditText和https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html
中提到的TextInputLayout答案 1 :(得分:0)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true">
<android.support.design.widget.TextInputLayout
android:id="@+id/inputPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:hint="@string/new_password"
android:background="@android:color/transparent"
android:paddingLeft="12dp"
android:textColor="@color/red"
android:textSize="12sp" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
答案 2 :(得分:0)
尝试将“编辑文字”的背景设置为透明
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Hello"
android:background="#00000000" />