Android Material Components是一个用于构建现代化、美观的Android应用界面的UI库。其中的TextInputLayout是一个用于包装EditText的容器,可以提供一些额外的功能和样式。
使用Android Material Components的TextInputLayout,可以通过XML设置未聚焦且不为空时的提示文本颜色。具体步骤如下:
implementation 'com.google.android.material:material:1.4.0'
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hint="请输入内容"
app:hintTextColor="@color/hint_text_color">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/text_color" />
</com.google.android.material.textfield.TextInputLayout>
在上述代码中,app:hint
属性用于设置提示文本,app:hintTextColor
属性用于设置提示文本的颜色。你可以将@color/hint_text_color
替换为你想要的颜色值。
setBoxStrokeColorStateList()
方法来改变未聚焦时的边框颜色。例如:TextInputLayout textInputLayout = findViewById(R.id.textInputLayout);
ColorStateList colorStateList = getResources().getColorStateList(R.color.box_stroke_color);
textInputLayout.setBoxStrokeColorStateList(colorStateList);
在上述代码中,R.color.box_stroke_color
是一个颜色资源,表示未聚焦时的边框颜色。
综上所述,使用Android Material Components的TextInputLayout,可以通过XML设置未聚焦且不为空时的提示文本颜色和边框颜色。更多关于Android Material Components的信息和使用方法,你可以参考腾讯云的相关产品文档:
领取专属 10元无门槛券
手把手带您无忧上云