[英]Change Line Color of EditText - Android
我可以更改EditText
上的线条颜色。 活跃时它有一些绿色。
是否可以仅在活动时更改线条的颜色,我该怎么做...?
您需要为编辑文本设置背景源。
EditText
android:background="@drawable/my_theme_edit_text"
等android:background="@drawable/my_theme_edit_text"
。 或者您可以在应用主题中设置该背景 - 您将在该网站的.zip文件中找到示例 这个给你:
editText.getBackground().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
添加到您的themes.xml这一行:
<item name="colorAccent">@color/black</item>
这将设置colorControlActivated
的默认颜色,用于着色小部件
您可以将edittext的背景设置为一个矩形,在左侧,右侧和顶部使用减去填充来实现此目的。
下面是为聚焦和非聚焦的edittext设置不同线条颜色的xml示例,只需将其设置为edittext的背景。
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="-2dp"
android:left="-2dp"
android:right="-2dp"
android:bottom="2dp">
<selector >
<item android:state_enabled="true"
android:state_focused="true">
<shape
android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#6A9A3A"/>
</shape>
</item>
<item android:state_enabled="true">
<shape
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#000000"/>
</shape>
</item>
</selector>
</item>
</layer-list>
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:background="@drawable/text"
android:ems="10"
android:textColorHint="#fefefe"
android:hint="@string/text1"
android:textColor="#fefefe"
android:inputType="textEmailAddress"
android:layout_marginTop="10dp"
/>
在res / drawable / text.xml中使用以下代码
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="24.0dp">
<shape >
<solid android:color="#fefefe" />
</shape>
</item>
</layer-list>
你可以设置android:backgroundTint =“@ color / blue”来改变Edittext底线的颜色
您可以使用android:background = "@color/black" for the api 21
或以上21(这将适用于lollypop设备或以上版本),对于以下版本,您应该使用该样式的edittext。
我有同样的问题通过改变backgroundTint的颜色解决它如下 -
机器人:backgroundTint = “@颜色/ light_color”
如果您使用EditInxt的TextInputLayouts,我们应该更改以下属性。
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">@color/your color</item>
<item name="colorControlHighlight">@color/your color</item>
默认情况下,color是colorAccent。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.