[英]How to change bottom line color of EditText in Android?
I have tried changing my edit text bottom color various of ways but it doesn't change. 我尝试过多种方式更改我的编辑文本底部颜色,但它没有改变。 I do not want to use drawable.
我不想使用drawable。
here is my xml and the methods I have tried using. 这是我的xml和我尝试过的方法。
method one: 方法一:
android:backgroundTint="@color/colorPrimary"
method two: 方法二:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorControlNormal">@color/colorPrimary</item>
<item name="colorControlActivated">@color/colorPrimary</item>
<item name="colorControlHighlight">@color/colorPrimary</item>
</style>
</resources>
Here's my xml: 这是我的xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res /android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/b"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.isaac.loginexamples.b">
<RelativeLayout
android:background="#009688"
android:layout_width="match_parent"
android:layout_height="@dimen/relative_half_screen_height">
</RelativeLayout>
<android.support.v7.widget.CardView
card_view:cardElevation="18dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="@dimen/card_view_width"
android:layout_height="@dimen/card_view_height">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/header_logo_two"
android:background="#22313F"
android:layout_width="match_parent"
android:layout_height="@dimen/view_header_height"></View>
<View
android:background="@drawable/shadow"
android:layout_below="@+id/header_logo_two"
android:layout_width="match_parent"
android:layout_height="7dp"></View>
<ImageView
android:layout_marginTop="25dp"
android:layout_centerHorizontal="true"
android:id="@+id/logo_two"
android:background="@mipmap/ic_launcher"
android:layout_width="@dimen/logo_image_width_height"
android:layout_height="@dimen/logo_image_width_height" />
<EditText
android:backgroundTint="@color/colorPrimary"
android:id="@+id/username"
android:layout_marginTop="15dp"
android:layout_centerHorizontal="true"
android:layout_below="@+id/logo_two"
android:layout_width="270dp"
android:layout_height="45dp"
android:inputType="textEmailAddress" />
<EditText
android:layout_marginTop="8dp"
android:layout_alignLeft="@+id/username"
android:layout_below="@+id/username"
android:layout_width="240dp"
android:layout_height="45dp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
I have tried those two methods that I have seen online but it doesn't work. 我已经尝试过我在网上看过的那两种方法,但它不起作用。 I am running the latest version of Android Studio.
我正在运行最新版本的Android Studio。 I hope there is a solution.
我希望有一个解决方案。 NOTE: I DO NOT WANT TO USE A DRAWABLE.
注意:我不想使用可绘制的。 Thank you very much !
非常感谢你 !
If you don't want to use drawable, you can use "View" below edittext and change the color of that View
based on focuschange of edittext 如果您不想使用drawable,可以使用edittext下面的“View”,并根据edittext的focuschange更改该
View
的颜色
<View
android:id="@+id/username_view"
android:layout_width="match_parent"
android:layout_height="@dimen/size_1"
android:layout_alignEnd="@+id/username"
android:layout_alignLeft="@+id/username"
android:layout_alignRight="@+id/username"
android:layout_alignStart="@+id/username"
android:layout_below="@+id/username"
android:background="@color/grey"/>
within your activity or fragment, add these lines of code that takes care of changing the color of view based on username focus change 在您的活动或片段中,添加这些代码行,负责根据用户名焦点更改来更改视图的颜色
@OnFocusChange(R.id.username)
void onUserNameFocusChanged(View v, boolean hasFocus) {
if (userNameView != null) {
int focusViewColor = hasFocus ? getResources().getColor(R.color.red) : getResources().getColor(R.color.grey);
userNameView.setBackgroundColor(focusViewColor);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.