EditText背景基线颜色根据其在Android中的焦点而变化 [英] EditText background base line color changing based on its focus in android

查看:164
本文介绍了EditText背景基线颜色根据其在Android中的焦点而变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要设计EditText,使其具有下图所示的基线,当它获得焦点时,它将变为其他颜色.

我正在使用以下内容.

 <EditText    
    android:id="@+id/mobilenumber" 
    android:drawableLeft="@drawable/mobile"
    android:drawablePadding="15dp" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:background="@drawable/edt_bg"
    android:singleLine="true"
    android:textColorHint="#FFFFFF"
    android:hint="@string/mobilenumber"
    android:layout_marginTop="20dp"
    android:layout_gravity="center"
    android:padding="5dp"
    android:imeOptions="actionNext"
    android:maxLength="10"
    android:textColor="#ffffff"
    android:textCursorDrawable="@null"

    />

所以,请指导我如何处理.

解决方案

您可以为EditText添加主题

<style name="EditTextTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorControlNormal">@color/primary</item>
    <item name="colorControlActivated">@color/primary</item>
    <item name="colorControlHighlight">@color/primary</item>
</style>

而且您可以在EditText中使用

<EditText
    android:id="@+id/edtCode"
    android:layout_width="match_parent"
    android:layout_height="40dp"
   .......................
    android:theme="@style/EditTextTheme">

</EditText>

I need to design EditText with base line showed in below image and it will be change to some other color when it receives focus.!

i am using the following.

 <EditText    
    android:id="@+id/mobilenumber" 
    android:drawableLeft="@drawable/mobile"
    android:drawablePadding="15dp" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:background="@drawable/edt_bg"
    android:singleLine="true"
    android:textColorHint="#FFFFFF"
    android:hint="@string/mobilenumber"
    android:layout_marginTop="20dp"
    android:layout_gravity="center"
    android:padding="5dp"
    android:imeOptions="actionNext"
    android:maxLength="10"
    android:textColor="#ffffff"
    android:textCursorDrawable="@null"

    />

So, please guide me how to handle this.

解决方案

You can add theme for EditText

<style name="EditTextTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorControlNormal">@color/primary</item>
    <item name="colorControlActivated">@color/primary</item>
    <item name="colorControlHighlight">@color/primary</item>
</style>

And you can use in EditText as

<EditText
    android:id="@+id/edtCode"
    android:layout_width="match_parent"
    android:layout_height="40dp"
   .......................
    android:theme="@style/EditTextTheme">

</EditText>

这篇关于EditText背景基线颜色根据其在Android中的焦点而变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆