我想实现点击一个按键 跳转到Clipboard剪切板的界面, 然后剪切粘贴,能实现这个功能么?

解决方案 »

  1.   


     ClipboardManager clipboard =(ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
     clipboard.setText("some thing");
      

  2.   

    to dinjay: 我是想点击一个button 打开剪切板功能,执行完你的两行代码,怎么什么反应也没有啊, 这个剪切板究竟是个什么样的界面
      

  3.   

    ?剪贴板?android没有这个带UI的系统功能界面吧?要自己做的
      

  4.   

    Clipboard剪切板的界面中显示什么?
      

  5.   

    3.0版本中自带剪切板的功能, 但是只有选择一些字符后,剪切板才能显示出来,我现在想实现 点击一个button就让他弹出剪切板, 我觉得是不是应该提供这样的API函数啊,点击button时调用这个函数就行了,但是没找到这样的函数。
      

  6.   

    自带的剪切板中显示:Done,Text select, select all, cut, copy, paste这些
      

  7.   

    Intent.java:仿照ACTION_AIRPLANE_MODE_CHANGED
    @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));
      

  8.   

    private boolean startSelectionActionMode() {
            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;
        }
      

  9.   

    @Override
        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;
        }
      

  10.   

    public void onReceive(Context context, Intent intent) {
            if((isFocused() == true)&&(getWindowVisibility()==VISIBLE))
            {
    if (startSelectionActionMode()) {
      performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
      mDiscardNextActionUp = true;
      }
               }