【问题标题】:Cursor not visible in EditText in HTC devices光标在 HTC 设备的 EditText 中不可见
【发布时间】:2014-11-17 07:30:02
【问题描述】:

在我的应用程序中,我使用 EditText 的光标颜色。

它在 三星设备 中工作,但在 HTC One 中没有显示。如果我将 textCursorDrawable 元素设置为 null,它会将默认文本颜色显示为光标颜色,但我需要红色光标颜色。

我无法找到问题所在。 请任何人帮助我。

这是我的 XML 代码中的EditText

<EditText
    android:id="@+id/username_edit"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_weight="90"
    android:background="@null"
    android:ems="10"
    android:hint="user name"

    android:maxLength="60"
    android:paddingLeft="5dp"
    android:singleLine="true"
    android:textColor="@color/black"
    android:textCursorDrawable="@color/appheader_color"
    android:textSize="@dimen/TextSize_medium" >

</EditText>

【问题讨论】:

  • 你用的是什么安卓版本?
  • 对于我使用的应用程序,minsadVersion 为 8,最大值为 19 htc 移动版本为 4.4.2

标签: android android-edittext


【解决方案1】:

尝试添加

android:textCursorDrawable="@null"

<EditText  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textCursorDrawable="@drawable/color_cursor"
    />

在drawable中你可以设置自己的颜色

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <size android:width="1dp" />
    <solid android:color="#FFFFFF"  /> //#FFFFFF will be replaced by your color code
</shape>

【讨论】:

【解决方案2】:

试试这个。它可能会帮助你。

创建drawalble xml:cursor_color

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <size android:width="3dp" />
    <solid android:color="#FF0000"  />
</shape>

在编辑文本中:

<EditText
                    android:id="@+id/username_edit"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="90"
                    android:background="@null"
                    android:ems="10"
                    android:hint="user name"

                    android:maxLength="60"
                    android:paddingLeft="5dp"
                    android:singleLine="true"
                    android:textColor="@color/black"
                    android:textCursorDrawable="@drawable/cursor_color"
                    android:textSize="@dimen/TextSize_medium" >


                </EditText>

【讨论】:

猜你喜欢
  • 2017-10-31
  • 1970-01-01
  • 2013-08-22
  • 2015-08-03
  • 1970-01-01
  • 2013-03-26
  • 2015-07-10
  • 2012-02-24
  • 2015-12-17
相关资源
最近更新 更多