Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 聚焦时,TextInputLayout下划线颜色不适应自定义颜色_Android_Android Textinputlayout_Material Components Android_Material Components_Textinputlayout - Fatal编程技术网

Android 聚焦时,TextInputLayout下划线颜色不适应自定义颜色

Android 聚焦时,TextInputLayout下划线颜色不适应自定义颜色,android,android-textinputlayout,material-components-android,material-components,textinputlayout,Android,Android Textinputlayout,Material Components Android,Material Components,Textinputlayout,不确定我遗漏了什么,但每次edittext聚焦时,下划线颜色都不适合我设置的自定义颜色。这里是我的主题代码供参考 <style name="EditTextHintWhite" parent="@style/AppTheme"> <item name="color">@color/white</item> <item name="android:textColorHint">@color/white</item> &l

不确定我遗漏了什么,但每次
edittext
聚焦时,下划线颜色都不适合我设置的自定义颜色。这里是我的主题代码供参考

<style name="EditTextHintWhite" parent="@style/AppTheme">
   <item name="color">@color/white</item>
   <item name="android:textColorHint">@color/white</item>
   <item name="colorControlNormal">@color/white</item>
   <item name="colorControlActivated">@color/white</item>
   <item name="colorError">@color/white</item>
</style>

填充框样式的下划线颜色由属性定义。可以将其添加到布局或自定义样式中。比如:

<style name="...." parent="Widget.MaterialComponents.TextInputLayout.FilledBox" >
    <!-- underline color in FilledBox style -->
    <item name="boxStrokeColor">@color/custom_selector_filled_stroke_color</item>
    ....
</style>
使用(删除父项):


@颜色/白色
@颜色/。。。
@颜色/。。。
如果您想要自定义下划线,请在
TextInputLayout
中使用
app:boxStrokeColor=“@color/text\u input\u layout\u stroke\u color”
属性


注意:使用
com.google.android.material.textfield.textinputtext
而不是我找到的
androidx.appcompat.widget.AppCompatEditText
。我希望这是你的解决办法。你的建议我都做了,但还是不起作用。是否有理由使用
com.google.android.material.textfield.textinputtext
而不是
androidx.appcompat.widget.AppCompatEditText
?该
textinputtex
设计用于
com.google.android.material.textfield.textinputtelayout
的子版本,并扩展了
AppCompatEditText
。为什么要在
编辑文本中使用
应用程序:backgroundTint
?不管怎么说,我刚刚试过,效果不错。检查你的风格。你使用的是1.1.0-beta01吗?如果你是说
1.1.0-beta01
是你所说的
com.google.android.material
依赖关系,那么是的,我也尝试了
1.0.0
,但没有任何区别。我只是复制了你的代码,除了颜色values@philip在你的代码中有一些不起作用的东西。只需尝试一个带有简单TIL和boxStrokeColor的空项目。我也用你的代码更新了答案,但做了一些改变。它起作用了。
<style name="...." parent="Widget.MaterialComponents.TextInputLayout.FilledBox" >
    <!-- underline color in FilledBox style -->
    <item name="boxStrokeColor">@color/custom_selector_filled_stroke_color</item>
    ....
</style>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:color="?attr/colorPrimary" android:state_focused="true"/>
  <!-- 4% overlay over 42% colorOnSurface -->
  <item android:alpha="0.46" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
  <item android:alpha="0.38" android:color="?attr/colorOnSurface" android:state_enabled="false"/>
  <item android:alpha="0.42" android:color="?attr/colorOnSurface"/>
</selector>
    <com.google.android.material.textfield.TextInputLayout
        android:hint="@string/email"
        android:theme="@style/EditTextHintWhite"
        ..>

        <com.google.android.material.textfield.TextInputEditText
            android:inputType="textEmailAddress"
            android:maxLines="1"
            android:textColor="@color/white"
            ../>

    </com.google.android.material.textfield.TextInputLayout>
  <style name="EditTextHintWhite">
    <item name="colorError">@color/white</item>
    <item name="colorPrimary">@color/...</item>
    <item name="colorOnSurface">@color/...</item>
  </style>