Android的:如何使TextView的编辑? [英] Android: How to make TextView editable?

查看:162
本文介绍了Android的:如何使TextView的编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能让用户编辑的TextView ?当然,我可以使用的EditText 代替,但我不知道如何来定制它,我也读过Android中文档的TextView 可编辑。所以,我想这样的:

How can I allow user to edit a TextView? Of course, I can use EditText instead, but I don't know how to customize it and also I've read in Android documentation that TextView can be editable. So I tried this:

<TextView android:id="@+id/tv"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="80sp"
          android:text="MyText"
          android:editable="true"
          android:singleLine="true"
          android:inputType="text"
          android:focusable="true"
          android:clickable="true"
          android:cursorVisible="true"/>

但它仍然看起来像普通的TextView 。有谁知道我错过了什么?或者,可能是,如何定制的EditText 它看起来像的TextView :无边框和背景

But it still looks like common TextView. Does anyone know what I have missed? Or, may be, how to customize EditText for it look like TextView: without borders and background?

推荐答案

我知道你不希望使用的EditText ,但它真的很容易使它看起来像一个的TextView

I know you don't want to use an EditText but it's really easy to make it look like a TextView.

<EditText
     android:id="@+id/Id"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:background="@android:color/transparent" >
 </EditText>

您也可以使用机器人:背景=@空

编辑:

的TextView 编辑参数的没有的使其可编辑(有一些限制条件)。

The TextView's editable param does make it editable (with some restrictions).

如果您设置机器人:编辑=真正的您可以通过方向键访问的TextView ,或者你可以添加机器人:focusableInTouchMode =真正的来能够获得专注于触摸

If you set android:editable="true" you can access the TextView via the D-pad, or you could add android:focusableInTouchMode="true" to be able to gain focus on touch.

现在的问题是,你不能修改现有的文字,你不能移动光标。 你刚才写的文字被现有文本之前添加。

The problem is you cannot modify the existing text, and you cannot move the cursor. The text you write just gets added before the existing text.

这篇关于Android的:如何使TextView的编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆