我想在xamarin Android中用红色星号向textinputlayout添加一个必填字段。对此有任何想法。我试图在Google中找到但没有任何解决方案。
答案 0 :(得分:0)
要将星号添加到TextView
中,您需要使用SpannableStringBuilder
。请参考此处显示的代码:
var txt = FindViewById<EditText>(Resource.Id.textInputEditText1);
TextView text = (TextView)FindViewById(Resource.Id.textView1);
string simple = "CREATE PASSWORD";
string colored = "*";
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.Append(simple);
int start = builder.Length();
builder.Append(colored);
int end = builder.Length();
builder.SetSpan(new ForegroundColorSpan(Color.Red), start, end,SpanTypes.ExclusiveExclusive);
text.SetText(builder, TextView.BufferType.Normal);
axml代码
<TextView
android:text="Create Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1" />
<EditText
android:layout_width="match_parent"
android:text="123456767888"
android:layout_height="wrap_content"
android:id="@+id/textInputEditText1"
android:password="true" />
输出屏幕截图