具有自定义主题的EditText在选择句柄下显示下划线 [英] EditText with custom theme shows underline under selection handle

查看:118
本文介绍了具有自定义主题的EditText在选择句柄下显示下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过应用主题来修改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:

<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?

推荐答案

您可以将此样式用作

<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在选择句柄下显示下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆