33
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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("复制成功");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user