2016-08-19 72 views
2

如何在對話框中打開時刪除默認的EditText的矩形邊框? 我嘗試了將背景設置爲null,但它沒有奏效。當我在對話框中使用它時,只會出現EditText這個矩形邊框。在對話框中打開時刪除默認的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(); 

enter image description here

+1

要刪除EditText中的邊框,請在EditText中提供可繪製的背景。加上TextInputEditText與TextInputLayout中提到的https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html – Ramit

+0

嘗試android:background =「@ null」在您的edittext – kgandroid

+0

@kgandroid已經嘗試..不工作 –

回答

0

enter image description here 我用你的代碼來生成一個對話框。這就是我得到的。

<?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> 
+0

不能正常工作..... –

+0

能不能顯示一些截圖,你想怎麼樣?之前和之後 – kggoh

+0

圖像添加在question.i希望它出現,因爲它正常顯示(如果不用在對話框中)沒有那個矩形背景 –

0

嘗試編輯文本的背景設置爲透明

<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:hint="Hello" 
    android:background="#00000000" /> 
+0

已經嘗試..不工作 –