Android 如何使用红色Astrick标记制作TextInputLayout
我试图使用TextInputLayout来设置必填字段。我使用了Spanable类,但以单色显示TextInputLayout的提示。我希望我的视图看起来像下面的链接Android 如何使用红色Astrick标记制作TextInputLayout,android,android-layout,Android,Android Layout,我试图使用TextInputLayout来设置必填字段。我使用了Spanable类,但以单色显示TextInputLayout的提示。我希望我的视图看起来像下面的链接 我创建了以下文本InputItemText,使其看起来尽可能类似于“材质设计”文本字段 XML布局 <android.support.design.widget.TextInputLayout android:id="@+id/etlayout" and
我创建了以下文本InputItemText,使其看起来尽可能类似于“材质设计”文本字段 XML布局
<android.support.design.widget.TextInputLayout
android:id="@+id/etlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
app:counterMaxLength="25">
<android.support.design.widget.TextInputEditText
android:id="@+id/et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:layout_marginLeft="-4dp"
android:layout_marginStart="-4dp"
android:layout_marginTop="8dp"
android:textSize="16sp"
android:inputType="text|textCapSentences"
android:singleLine="true"
android:hint="@string/title"
android:textColorHint="@color/transparent38"/>
</android.support.design.widget.TextInputLayout>
对不起,这不是StackOverflow的工作方式。形式为“我想做X,请给我提示和/或示例代码”的问题被认为是离题的。请访问并阅读,特别是阅读Why is
<color name="transparent38">#66000000</color>
etlayout = (TextInputLayout)findviewbyid(R.id.etlayout);
TextWatcher twTitle = new TextWatcher() { //Analyzes when the view changes
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (true) { //Replace condition with validity test
etlayout.setErrorEnabled(false); //Removes the extra space
etlayout.setError(null); //Removes the error message
} else { //If the text is not valid
etlayout.setErrorEnabled(true); //Makes the space for the error appear
etlayout.setError("Invalid input"); //Shows a message
}
}
@Override
public void afterTextChanged(Editable s) {
}
};
etTitle.addTextChangedListener(twTitle);