如何让td只读不可编辑extView不可编辑

iOS 问题:求教,我用textview显示了一长段文字(设置为不可编辑,不可选择),请问如何改变textview中一部分部分字体的颜色(不是所有文字,是开发时就指定的一部分文字) -
求教,我用textview显示了一长段文字(设置为不可编辑,不可选择),请问如何改变textview中一部分部分字体的颜色(不是所有文字,是开发时就指定的一部分文字)
共有 1 个回答
OHAttributedLabel这个三方库 或者用这个 &a href=&/mattt/TTTAttributedLabel& class=&c4alink& target=&_blank&&/mattt/TTTAttributedLabel&/a&
登录后方可回复
登录后方可回答android:editable&is&deprecated:&Use&an&&EditText&&to&make&it&editable
android:editable is deprecated: Use inputType&instead
分析:关于EditText控件的read-only问题,即: 无法通过UI更改其中的内容, 但可以选定部分内容, 进行复制.在早期的sdk, EditText有Editable属性, 现在这个属性已经deprecated了.
解决方法:
其实只需一行代码就能搞定et.setKeyListener(null);
注意, 这里不是setOnKeyListener, 而是setKeyListener. 此方法是TextView的成员, 调用后的效果完全符合预期, 并且获得焦点后不会弹出输入法.&
下面是官方文档的解释
Sets the key listener to be used with this TextView. This can be null to disallow user input. Note that this method has significant and subtle interactions with soft keyboards and other input method: see KeyListener.getContentType() for important details. Calling this method will replace the current content type of the text view with the content type returned by the key listener.
Be warned that if you want a TextView with a key listener or movement method not to be focusable, or if you want a TextView without a key listener or movement method to be focusable, you must call setFocusable again after calling this to get the focusability back the way you want it.
阅读(...) 评论()Posts - 218,
Articles - 0,
Comments - 1676
09:05 by 贺臣, ... 阅读,
一. 新建一个Activity 和 Layout
  首先在layout文件夹中新建一个activity_main.xml,在新建工程的时候一般默认会新建此xml文件,修改其代码如下:
&RelativeLayout xmlns:android="/apk/res/android"
xmlns:tools="/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" &
android:id="@+id/lblTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="88dp"
android:layout_marginTop="51dp"
android:text="TextView" /&
&/RelativeLayout&
activity_main.xml 代码
  修改MainActivity.java文件代码如下:
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView lblTitle=(TextView)findViewById(R.id.lblTitle);
lblTitle.setText("这是显示的内容");
MainActivity.java 代码
  通过以上方法就可以修改TextView中的显示文字内容了
二. 显示连接文字
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView lblTitle=(TextView)findViewById(R.id.lblTitle);
lblTitle.setText("&a href=\"\"&百度&/&");
显示连接字符串
  修改如上代码,然后运行查看手机界面,发现并没有自动以Html格式来解析此字符串,说明TextView模式是不支持Html字符串解析的
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView lblTitle=(TextView)findViewById(R.id.lblTitle);
lblTitle.setAutoLinkMask(Linkify.ALL);
lblTitle.setText("&a href=\"\"&百度&/&");
解析带有http的文字
  我们可以通过setAutoLinkMask 来设置带有连接的字符串,或者使用如下代码:
&RelativeLayout xmlns:android="/apk/res/android"
xmlns:tools="/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" &
android:id="@+id/lblTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="88dp"
android:layout_marginTop="51dp"
android:autoLink="all"
android:text="TextView" /&
&/RelativeLayout&
连接文字显示

我要回帖

更多关于 如何让td只读不可编辑 的文章

 

随机推荐