要在TextInputLayout中更改文本颜色,可以使用TextInputEditText的setTextColor()方法来设置文本的颜色。
首先,确保项目中已经添加了Material Components库的依赖项。在build.gradle文件中的dependencies块中添加以下代码:
implementation 'com.google.android.material:material:1.4.0'
接下来,在布局文件中使用TextInputLayout和TextInputEditText组合来创建文本输入框。例如:
在代码中,通过findViewById()方法获取TextInputEditText实例,并使用setTextColor()方法来设置文本的颜色。例如:
TextInputEditText textInputEditText = findViewById(R.id.textInputEditText);
textInputEditText.setTextColor(getResources().getColor(R.color.textColor));
在上面的代码中,"textColor"是一个在colors.xml文件中定义的颜色资源。
这样,就可以在TextInputLayout中更改文本颜色了。