【发布时间】:2018-03-05 19:29:02
【问题描述】:
我正在尝试以编程方式更改单个 EditText 的全息下划线颜色。我已经尝试了所有可以在 SO 上找到的示例,但似乎没有任何效果。这是我最近和最好的尝试:
编辑:当前代码:
txtName.Background.ClearColorFilter();
txtName.Background.SetColorFilter(Android.Graphics.Color.ParseColor("#ff0000"), PorterDuff.Mode.SrcIn);
我也尝试过只使用txtName.Background.SetTint(Resource.Color.colorRed),但这也不起作用。
EditText XML:
<EditText
android:id="@+id/input_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "
android:maxLength="30"
android:singleLine="true"
android:scrollHorizontally="true"
android:hint="Name"
android:textColor="#8c8c8c"
android:textColorHint="#8c8c8c"
app:backgroundTint="#22d6d3"
android:layout_marginBottom="10dp" />
编辑 - 这是最终工作的代码:
ViewCompat.SetBackgroundTintList(txtName, Android.Content.Res.ColorStateList.ValueOf(Color.Red));
【问题讨论】:
-
我已经回答了试试看
标签: android xamarin xamarin.android