【问题标题】:Edit text cursor show bottom line编辑文本光标显示底线
【发布时间】:2017-05-18 07:49:46
【问题描述】:

我已将样式应用于我的 EditText 以在未选择时更改底线,我这样做:

<style name="JoinMeetingEditText" parent="Widget.AppCompat.EditText">
    <item name="colorControlNormal">@color/edit_text_no_selected_color</item>
    <item name="android:textCursorDrawable">@null</item>
    <item name="android:theme">@style/JoinMeetingEditText</item>
</style>

但是EditText中的光标是这样显示的

如果我删除&lt;item name="android:theme"&gt;@style/JoinMeetingEditText&lt;/item&gt;,则不会显示该行,但我的编辑文本在未选择时不会显示正确的颜色

这就是我在 XMl 中定义 EditText 的方式

 <android.support.design.widget.TextInputLayout
        style="@style/JoinMeetingTextInputLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/email"
            android:theme="@style/JoinMeetingEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Email"
            android:inputType="number"
            android:textColor="@color/white"
            android:textSize="16sp">

            <requestFocus />
        </EditText>

【问题讨论】:

  • 发送您的完整 xml 以用于该 editTest 字段。
  • 添加了编辑文本 xml 定义

标签: android android-edittext


【解决方案1】:

您可以像这样创建自定义可绘制对象

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item 
    android:state_pressed="true"
    android:color="@color/colorAccent"
    /> <!-- pressed -->    
<item 
    android:state_focused="true"
    android:color="@color/colorPrimary"
    /> <!-- focused -->    
<item 
    android:drawable="@android:drawable/edittext_normal" 
    /> <!-- default -->
</selector>

将此自定义样式用于该编辑文本的背景。这可能会对您有所帮助。

【讨论】:

  • 它不起作用。错误:原因:org.xmlpull.v1.XmlPullParserException:二进制 XML 文件第 4 行: 标签需要“drawable”属性或定义可绘制对象的子标签
【解决方案2】:

在全局“AppTheme”上更改自定义主题的父级,如下所示: parent="AppTheme"

或常见主题,例如: parent="Theme.AppCompat.Light.NoActionBar"

在您的情况下,自定义主题用作所有 EditText 子视图(包括光标视图)的主题。当您将 AppTheme 设置为父级时,它会与 EditText 属性上的光标视图的特殊属性重叠。

希望对你有帮助。

【讨论】:

    【解决方案3】:

    我有同样的问题。以下是我的解决方法:https://stackoverflow.com/a/44036429/1439957

    附:我建议使用TextInputEditText 作为TextInputLayout 的子代,而不是EditText,因为TextInputEditTexts 是专门为此设计的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-23
      • 1970-01-01
      • 2014-11-11
      • 1970-01-01
      • 1970-01-01
      • 2011-02-25
      • 1970-01-01
      相关资源
      最近更新 更多