将编辑文本下划线颜色更改为失去焦点和获得焦点时相同。

6

这里输入图片描述我的编辑文本下划线似乎总是在聚焦时突出显示,我一直在尝试让所有行的颜色与图片中第一行相同,这是我的XML代码,有谁知道如何使所有三行都突出显示(即使其他编辑文本没有聚焦)吗?提前感谢!!!

<EditText
        android:id="@+id/edit_password_second"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:textColor="@color/edit_text_color"
        android:backgroundTint="@color/edit_text_color"

下划线的颜色目前是相同的。改变的是线条的粗细,从视觉上看起来就像是不同的颜色。此外,它实际上略微更暗。 - Zoe stands with Ukraine
2个回答

10

你可以尝试添加一个主题

<style name="EditTextTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">@color/primary</item>
<item name="colorControlActivated">@color/primary</item>
<item name="colorControlHighlight">@color/primary</item>
</style>

并将其设置在你的EditText上

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/EditTextTheme">
</EditText>

嗨,Stamatis,感谢你的帮助,我已经尝试了这个,虽然它添加了一个打字行并删除了每行末尾的钩子,这不是什么大问题,但我想保留它们。你知道有什么解决方法吗? - DanielRM
检查一下这个答案。我没有尝试过,但我认为你应该试试看。https://dev59.com/0W455IYBdhLWcg3wAvXQ#4585750 - Stamatis Stiliats

2

前往 styles.xml 并将 <item name="colorAccent">#YOUR_COLOR</item> 更改为与您的 EditText 的 backgroundTint 相同的颜色。


感谢您的时间和建议。我已经尝试了您的建议,即使添加了colorAccent,未聚焦的编辑文本仍然是相同的较暗颜色。 - DanielRM

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接