You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android:Material TextInputLayout的app:boxStrokeColor属性为何不生效?

解决TextInputLayout边框颜色不生效的建议
  • 确认使用的是Material Components库的TextInputLayout,完整类名为com.google.android.material.textfield.TextInputLayout,而非AppCompat版本的组件。
  • 确保boxStrokeColor使用ColorStateList定义不同状态下的颜色,而非单一纯色。示例:
    在布局文件中引用颜色状态列表:
    <com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:boxStrokeColor="@color/text_input_stroke_color"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlineBox">
    
        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </com.google.android.material.textfield.TextInputLayout>
    
    在res/color/text_input_stroke_color.xml中定义状态颜色:
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:color="#FF4081" android:state_focused="true"/>
        <item android:color="#F44336" android:state_error="true"/>
        <item android:color="#9E9E9E"/> <!-- 默认未聚焦状态 -->
    </selector>
    
  • 检查TextInputLayout的样式:仅OutlineBox或FilledBox样式支持boxStrokeColor属性,需在布局中指定对应样式,如上述示例中的@style/Widget.MaterialComponents.TextInputLayout.OutlineBox。
  • 排查主题全局覆盖:检查styles.xml中的AppTheme,是否通过textInputStyle全局设置了boxStrokeColor,导致局部配置被覆盖。
  • 确认代码未动态覆盖:检查是否在Java/Kotlin代码中调用setBoxStrokeColor()等方法,覆盖了XML中的属性设置。

内容的提问来源于stack exchange,提问作者deja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 06:37:09