【问题标题】:TextView with a cursor带有光标的 TextView
【发布时间】:2013-10-02 10:18:05
【问题描述】:

我正在尝试创建一个应该有光标的自定义 TextView。我不想使用 EditText,因为输入不应该通过 android 键盘提供,而且它应该看起来像一个文本视图。

我发现 TextView 接口支持光标,但我无法让它显示。这是我尝试过的:

添加

android:textCursorDrawable="@null"

textView.setCursorVisible(true);
textView.setSelected(true);
textView.forceLayout();
textView.moveCursorToVisibleOffset();

当我添加 android:editable="true" 并调用 textView.moveCursorToVisibleOffset(); 在 textView 中抛出 NullPointerException。

有什么建议吗?

【问题讨论】:

  • @null 意味着它没有光标,不是吗?
  • 表示光标的颜色和文字的颜色一样,反正我试过了,有没有也有。
  • 你试过实际的颜色吗?

标签: android textview


【解决方案1】:

您可以像这样使用编辑文本,它显示为文本视图:

 <EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:background="@null"/>

【讨论】:

  • "输入不应通过安卓键盘提供"
  • 为此添加一行 android:focusable="false"
猜你喜欢
  • 2015-09-07
  • 2019-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多