Android:可复制内容的TextView、EditText
16lz
2021-01-24
可复制内容的TextView、EditText
有时候我们做app的时候,想要让用户可以复制一些文本内容。此时,网上有一些自定义TextView可以实现该功能。但是,不免有点麻烦。其实,直接设置xml属性就可以实现该功能。
- xml代码
- 效果图
- 属性说明
xml代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" tools:context="com.xu.tvBeCopy.MainActivity" > <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:cursorVisible="false" android:inputType="none" android:text="朋友,你怎么这么帅啊!!!!" android:textColor="#000000" android:textIsSelectable="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="我是TextView美女!!!" android:textColor="#000000" android:textIsSelectable="true" />LinearLayout>
效果图:
EditText:
TextView:
属性说明
android:textIsSelectable=”true”属性是在API 11之后才有的。如果设置成true,长按后就可以进行文字的复制粘贴。
EditText的android:inputType=”none”是为了不能让用户输入内容。
EditText的android:cursorVisible=”false”是为了隐藏掉输入框的光标。
EditText的android:background=”@null”是为了设置背景为空,隐藏掉输入框的下划线。
但是,注意一点,用了这个属性就不能用剪切功能。
更多相关文章
- Instant Run详解
- Android(安卓)之 API级别
- Android样式研究
- 【Android源码】Android(安卓)UI 之一步步教你自定义控件
- Android(安卓)之 -- DRM(转)
- android:windowSoftInputMode 属性介绍
- 2018-03-10—Android六大布局之LinearLayout和RelativeLayout
- Android(安卓)SDK2.2离线安装
- Android(安卓)中自定义属性(attr.xml,TypedArray)的使用!