36 lines
958 B
Java
36 lines
958 B
Java
package cn.shangyu.gdxzExpert.utils;
|
|
|
|
import android.content.ClipData;
|
|
import android.content.ClipboardManager;
|
|
import android.content.Context;
|
|
import android.widget.TextView;
|
|
|
|
import static android.content.Context.CLIPBOARD_SERVICE;
|
|
|
|
/**
|
|
* Created by WANGChengXin on 2020/1/14.
|
|
*/
|
|
|
|
public class CopyButtonLibrary {
|
|
private ClipboardManager myClipboard;
|
|
private ClipData myClip;
|
|
private Context context;
|
|
private TextView textView;
|
|
|
|
public CopyButtonLibrary(Context context, TextView textView) {
|
|
this.context = context;
|
|
this.textView = textView;
|
|
}
|
|
|
|
public void init() {
|
|
myClipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
|
|
String text;
|
|
text = textView.getText().toString();
|
|
|
|
myClip = ClipData.newPlainText("text", text);
|
|
myClipboard.setPrimaryClip(myClip);
|
|
ToastUtil.showMessage("复制成功");
|
|
}
|
|
|
|
}
|