EditText with custom theme shows underline under selection handle(具有自定义主题的 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
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 在选择句柄下显示下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:具有自定义主题的 EditText 在选择句柄下显示下划
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
