如何在TextView中的文本末尾显示光标? [英] How to display cursor at the end of text in TextView?
问题描述
我想在TextView的文本末尾显示闪烁的光标.
I wanted to display blinking cursor at the end of the text in TextView .
我在TextView中通过 android:cursorVisible ="true"
尝试过,但没有成功.
I tried by android:cursorVisible="true"
in TextView But no go .
即使我尝试了 text.setCursorVisible(true);
也不起作用.
Even i tried text.setCursorVisible(true);
Doesn't work .
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cursorVisible="true"
android:textCursorDrawable="@null" />
有人知道任何解决方案吗?
Does any one know any solution for it ?
推荐答案
首先,您应使用 EditText
代替 TextView
进行输入.如果光标仍然不闪烁,请在 xml文件
中设置 android:cursorVisible ="true"
属性,它将使光标闪烁.如果您的光标在编辑文本中不可见,这也是一个看不到光标闪烁的原因.设置 android:textCursorDrawable ="@ null"
.这应该可以解决您的问题
First of all you should use EditText
in place of TextView
for taking input. If still the cursor doesn't blink, set the android:cursorVisible="true"
attribute in xml file
, it should make the cursor blink. If your cursor is not visible in edit text, that's also a reason one can't see the cursor blinking. Set android:textCursorDrawable="@null"
. This should solve your problem
<EditText
android:id="@+id/editext1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textCursorDrawable="@null"
android:cursorVisible="true">
</EditText>
在您的活动班级中,也添加此代码.
In your activity class, add this code as well.
EditText input = (EditText)findViewById(R.id.edittext1);
input.setSelection(input.getText().length());
这篇关于如何在TextView中的文本末尾显示光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!