Android TextView长按复制实现,Android复制文本
生活随笔
收集整理的這篇文章主要介紹了
Android TextView长按复制实现,Android复制文本
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?代碼調用系統復制粘貼板
//獲取剪貼板管理器:ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); // 創建普通字符型ClipDataClipData mClipData = ClipData.newPlainText("Label", "這里是要復制的文字"); // 將ClipData內容放到系統剪貼板里。cm.setPrimaryClip(mClipData);?
自定義textview
?
import android.content.Context; import android.util.AttributeSet; import android.widget.EditText;public class NewTextView extends EditText {public NewTextView(Context context) {super(context);// TODO Auto-generated constructor stub}public NewTextView(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stub}public NewTextView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);// TODO Auto-generated constructor stub}@Overrideprotected boolean getDefaultEditable() {//禁止EditText被編輯return false;} }layout文件應用
?
<com.administrator.myhp.NewTextViewandroid:id="@+id/totwo"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@null"android:text="Hello World!" />Java代碼
?
NewTextView textView = (NewTextView) findViewById(R.id.totwo); textView.setTextIsSelectable(true);?
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Android TextView长按复制实现,Android复制文本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: scrt 上传和下载文件
- 下一篇: IDEA的xml注释的顶格和空格问题