我想实现点击一个按键 跳转到Clipboard剪切板的界面, 然后剪切粘贴,能实现这个功能么?
解决方案 »
- android调用WebService的问题
- 求救!!MulticastSocket UDP组播,joinGroup 错误
- 急!我如何在android手机端解析webservice返回的dataset数据啊?急用
- adb又启动不了啦。。。。救命呀。。。
- 开发一个android小游戏,播放背景音乐用哪个类实现最好
- android 开发listview中实现仿新浪微博和人人推荐关注的ui设计
- 安卓如何实现这个效果
- 手机上的指南针怎么校准?
- android sqlite数据库问题
- 为什么APP连上WIFI就请求数据很慢!就算是3G网络都比WIFI快的多!
- 关于CPP做的JNI接口问题
- android menu问题
ClipboardManager clipboard =(ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText("some thing");
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_TEXTVIEW_POP_PASTE = "android.intent.action.POP_PASTE";键盘实现的地方:
Intent intent = new Intent(Intent.ACTION_TEXTVIEW_POP_PASTE); mContext.sendBroadcast(intent);
TEXTVIEW.JAVA:
public TextView(Context context,
AttributeSet attrs,
int defStyle)这个构造的结尾处添加如下代码段
context.registerReceiver(
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
ClipboardManager clipboard =(ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText("Done,Text select, select all, cut, copy, paste");
}
},new IntentFilter(Intent.ACTION_TEXTVIEW_POP_PASTE));
if (mSelectionActionMode != null) {
// Selection action mode is already started
return false;
} if (!canSelectText() || !requestFocus()) {
Log.w(LOG_TAG, "TextView does not support text selection. Action mode cancelled.");
return false;
} if (!hasSelection()) {
// If selection mode is started after a device rotation, there is already a selection.
selectCurrentWord();
} ActionMode.Callback actionModeCallback = new SelectionActionModeCallback();
mSelectionActionMode = startActionMode(actionModeCallback);
final boolean selectionStarted = mSelectionActionMode != null; if (selectionStarted && !mTextIsSelectable) {
// Show the IME to be able to replace text, except when selecting non editable text.
final InputMethodManager imm = InputMethodManager.peekInstance();
if (imm != null) imm.showSoftInput(this, 0, null);
} return selectionStarted;
}
public boolean performLongClick() {
if (super.performLongClick()) {
mDiscardNextActionUp = true;
return true;
} // Long press in empty space moves cursor and shows the Paste affordance if available.
if (!isPositionOnText(mLastDownPositionX, mLastDownPositionY) &&
mInsertionControllerEnabled) {
final int offset = getOffset(mLastDownPositionX, mLastDownPositionY);
stopSelectionActionMode();
Selection.setSelection((Spannable)mText, offset);
getInsertionController().show(0);
mDiscardNextActionUp = true;
return true;
} if (mSelectionActionMode != null) {
if (touchPositionIsInSelection()) {
// Start a drag
final int start = getSelectionStart();
final int end = getSelectionEnd();
CharSequence selectedText = mTransformed.subSequence(start, end);
ClipData data = ClipData.newPlainText(null, selectedText);
DragLocalState localState = new DragLocalState(this, start, end);
startDrag(data, getTextThumbnailBuilder(selectedText), localState, 0);
stopSelectionActionMode();
} else {
updateSelectedRegion();
}
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
mDiscardNextActionUp = true;
return true;
} // Start a new selection
if (startSelectionActionMode()) {
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
mDiscardNextActionUp = true;
return true;
} return false;
}
if((isFocused() == true)&&(getWindowVisibility()==VISIBLE))
{
if (startSelectionActionMode()) {
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
mDiscardNextActionUp = true;
}
}