2015-11-16 51 views
0

我需要的EditText看起來像這樣:如何自定義EditText?

EditText

我有底線的顏色。 我很久沒有使用UI,我不記得如何去做。

有人知道嗎?

謝謝!

+0

可能重複:http://stackoverflow.com/questions/26574328/changing-edittext-bottom-line-color-with-appcompat-v7 –

回答

2

您可以使用下面drawable resource作爲backgroundEditText

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape android:shape="rectangle"> 
      <solid android:color="@android:color/transparent" /> <!--background color of box--> 

     </shape> 
    </item> 

    <item 
     android:top="-2dp" 
     android:right="-2dp" 
     android:left="-2dp"> 
     <shape> 
      <solid android:color="@android:color/transparent" /> 
      <stroke 
       android:width="1dp" 
       android:color="@color/bg_color" /> <!-- color of stroke --> 
     </shape> 
    </item> 
</layer-list> 
+0

的回答十分感謝!它的作品像一個魅力)) – Carlos

+0

@Carlos很高興它適合你。 :-) –

0

在設計支持庫推出了一款名爲TextInputLayout新的元素顯示在EditText上的浮動標籤。

TextInputLayout將android:hint的值分配給EditText並將其顯示爲浮動標籤。

要顯示它像你想,試試這個方法:

1 - 創建選擇:

<android.support.design.widget.TextInputLayout 
android:id="@+id/input_layout_password" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:theme="@style/yourThemeWithYourColor"> 

    <EditText 
     android:id="@+id/input_email" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="Email" /> 

</android.support.design.widget.TextInputLayout> 
0

以下方法對我的作品(我通過看Telegram源代碼,發現這個方法)像下面:

<?xml version="1.0" encoding="utf-8"?> 

    <selector xmlns:android="http://schemas.android.com/apk/res/android"> 
     <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/search_dark_activated" /> 
     <item android:state_focused="true" android:drawable="@drawable/search_dark_activated" /> 
     <item android:drawable="@drawable/search_dark" /> 
    </selector> 

這裏是九補丁繪項目:

enter image description here enter image description here

+1

也可以從** ../Android \ sdk \ platforms \ android-23 \ data \ res \ drawable **目錄中獲得相同的9修補程序。在此目錄中搜索** edit_text_material **。 –