2016-01-04 19 views
10

Tôi có một số EditText trong mã của mình và tôi muốn làm cho đường viền dưới cùng của nó mỏng hơn một chút. Không thể tìm thấy bất cứ điều gì về nó trong Internet, có lẽ bất cứ ai ở đây có thể giúp tôi với nó.Thay đổi kích thước của đường viền dưới EditText

Những gì tôi có: enter image description here

Những gì tôi muốn: enter image description here

+0

gạch dưới hoặc biên giới phía dưới? coz gạch chân là tài sản của phông chữ không gui – anshuVersatile

+0

@anshu Tôi nghĩ rằng những gì tôi có nghĩa là biên giới dưới cùng – Ron

Trả lời

22

Hãy thử như thế này cho các hiệu ứng tập trung:

edt_bg_selector.xml:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:drawable="@drawable/edt_bg_selected" android:state_focused="true"/> 
<item android:drawable="@drawable/edt_bg_normal" android:state_focused="false"/> 
</selector> 

edt_bg_normal.xml:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
<item 
    android:bottom="1dp" 
    android:left="-2dp" 
    android:right="-2dp" 
    android:top="-2dp"> 
    <shape android:shape="rectangle" > 
     <stroke 
      android:width="1px" 
      android:color="#FF000000" /> 

     <solid android:color="#00FFFFFF" /> 

     <padding 
      android:bottom="5dp" 
      android:left="5dp" 
      android:right="5dp" 
      android:top="5dp" /> 
    </shape> 
</item> 
</layer-list> 

edt_bg_selected.xm l:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
<item 
    android:bottom="1dp" 
    android:left="-2dp" 
    android:right="-2dp" 
    android:top="-2dp"> 
    <shape android:shape="rectangle" > 
     <stroke 
      android:width="1px" 
      android:color="#ff0000" /> 

     <solid android:color="#00FFFFFF" /> 

     <padding 
      android:bottom="5dp" 
      android:left="5dp" 
      android:right="5dp" 
      android:top="5dp" /> 
    </shape> 
</item> 
</layer-list> 

và thay đổi chỉnh sửa văn bản của bạn như:

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/edt_bg_selector" /> 
+0

một câu hỏi nữa, thuộc tính nào tôi phải thay đổi để làm cho người lên máy chỉ dày hơn một chút? @Srikanth – Ron

+0

Tôi không nghĩ rằng chúng tôi có thể vẽ mỏng hơn 1px có thể vẽ được vì nó là đơn vị cơ bản. bạn có thể đặt 0.01dp như thế. nhưng nó sẽ tròn thành 1px chỉ bằng cách sử dụng 'px = (int) (tỷ lệ * dp + 0.5)' công thức này có tỷ lệ '1 cho mdpi', '1,5 cho hdpi', '2 cho xhdpi' và '3 cho xxhdpi '. – Srikanth

+0

Nếu bạn muốn mỏng hơn 1px, hãy thử thay đổi màu có thể vẽ thành màu trong suốt hơn như '# 26000000'. kiểm tra 'http://stackoverflow.com/questions/15852122/hex-transparency-in-colors' để biết tỷ lệ phần trăm minh bạch. – Srikanth

3

Hãy thử như thế này dưới đây:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@null" 
     android:hint="Biografie" 
     android:textColorHint="#99000000" 
     android:drawableLeft="@drawable/quote_img" /> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="1px" 
     android:background="#80000000" /> 
</LinearLayout> 

Hoặc

giữ btm_line_shape.xml này trong thư mục drawable của bạn :

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
<item 
    android:bottom="1dp" 
    android:left="-2dp" 
    android:right="-2dp" 
    android:top="-2dp"> 
    <shape android:shape="rectangle" > 
     <stroke 
      android:width="1px" 
      android:color="#FF000000" /> 

     <solid android:color="#00FFFFFF" /> 

     <padding 
      android:bottom="5dp" 
      android:left="5dp" 
      android:right="5dp" 
      android:top="5dp" /> 
    </shape> 
</item> 
</layer-list> 

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:hint="Biografie" 
    android:textColorHint="#99000000" 
    android:background="@drawable/btm_line_shape" 
    android:drawableLeft="@drawable/quote_image" /> 
+0

Cảm ơn bạn, đã làm việc hoàn hảo! Bạn có biết làm thế nào tôi có thể cơ hội màu sắc tập trung của EditText khi nhấp vào nó? @Srikanth – Ron

+0

Kiểm tra điều này: http://stackoverflow.com/questions/23417443/change-border-color-when-edittext-is-focused – Srikanth

+0

thay đổi ở trên btm_line_shape.xml như trong liên kết này và áp dụng nó làm nền. – Srikanth

Các vấn đề liên quan