2017-03-05 129 views
0

如何为EditText创建永久下划线,并在关注后可以改变颜色? 我还没有在其他主题中找到答案。 我想实现这样的事情: enter image description here下划线编辑文本

+0

你有没有试过这个:http://stackoverflow.com/a/37101446/2632867 – Alvi

回答

0

您可以使用自定义样式为您的EditText在style.xml这样的 -

<!-- Edit text --> 
    <style name="editTextStyle" parent="Theme.AppCompat.Light.NoActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="android:textSize">@dimen/auth_text_paragraph_little</item> 
     <item name="android:layout_gravity">left</item> 
     <item name="android:focusable">true</item> 
     <item name="colorControlNormal">@color/editUnderLine</item> 
     <item name="colorControlActivated">@color/colorAccent</item> 
     <item name="colorControlHighlight">@color/colorAccent</item> 
     <item name="android:textColorHint">@color/hint</item> 
    </style> 

@color/editUnderLine是你想从color.xml文件中使用颜色的名称像为string.xml文件和文件dimen.xml

,并在你的XML使用自定义样式布局 -

    <EditText 
         android:id="@+id/edt_phone_number" 
         style="@style/editTextStyle" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="@dimen/auth_margin_half" 
         android:padding="@dimen/auth_margin_half_plus" 
         android:fontFamily="@string/auth_font_family_regular" 
         android:hint="@string/auth_mobile_number" 
         android:inputType="phone"/>