我正在尝试通过应用主题来修改 EditText 的下划线颜色.
i am trying to modify the underline color of a EditText by applying a theme.
风格:
<style name="MyTheme.EditText" parent="Widget.AppCompat.EditText">
<item name="colorControlActivated">@color/green</item>
</style>
编辑文本:
<EditText
android:id="@+id/editText_amount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_enter_amount"
android:theme="@style/MyTheme.EditText"/>
基本上它可以工作,但是当我尝试选择或移动光标时,选择句柄也会加下划线.您可以在屏幕截图中看到这一点.
Basically it works, but when i try to select or move the cursor the selection handle is also underlined. You can see this in the screenshot.
有人知道如何解决这个问题吗?
Does someone know how to fix this?
你可以把这个样式当作一个
You can use this style as a
<EditText
style="@style/MyTheme.EditText"/>
或者,您可以将主题分开以引用 editTextStyle 属性.
Or, you can separate your theme for referencing the editTextStyle attribute.
<style name="MyEditTextStyle" parent="Widget.AppCompat.EditText">
<item name="colorControlActivated">@color/green</item>
</style>
<style name="MyTheme.EditText">
<item name="editTextStyle">@style/MyEditTextStyle</item>
</style>
<EditText
android:theme="@style/MyTheme.EditText"/>
好的,但是这些下划线是从哪里来的?
android:theme
是 View 的一个属性,当您将样式设置为 android:theme
时,该样式将由具有上下文主题的 ContextThemeWrapper 包装,同时膨胀查看.
android:theme
is an attribute of View and when you set a style as android:theme
, that style will be wrapped by ContextThemeWrapper with context theme while in inflation of view.
这意味着,如果您将 android:theme
属性设置为包含 android:background
项目的样式
So that means, if you set android:theme
property with style that contains android:background
item like
<item name="android:background">@color/green</item>
此主题所有者的每个子视图都将具有绿色背景.
every child view of this theme owner will be have a green background.
"Widget.AppCompat.EditText"
是一种样式,并将 ?attr/editTextBackground
引用为 "android:background"
.而在 v21/values-21.xml 文件中,@drawable/abc_edit_text_material
被定义为 editTextBackground
.
"Widget.AppCompat.EditText"
is a style and references ?attr/editTextBackground
as a "android:background"
. And in v21/values-21.xml file @drawable/abc_edit_text_material
is defined as editTextBackground
.
因此,对于您的示例,@drawable/abc_edit_text_material
成为您的 EditText 和 SelectionHandlers 的背景.
So, for your example, @drawable/abc_edit_text_material
becomes a background of your EditText and SelectionHandlers.
这篇关于具有自定义主题的 EditText 在选择句柄下显示下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!