android EditText編輯操作

        /*系統通過光標獲取對象*/

      View view = ((Activity)mContext).getCurrentFocus();

             if(viewCopy instanceof EditText){//判斷是不是EditText
                     EditText  edit = (EditText) view;
                     int start = edit.getSelectionStart();
                     int end = edit.getSelectionEnd();
                     if(start>end){//因爲光標選取EditText中內容時可能會從不同方向(左右)開始選取,讀取內容時從光標起始位置開始讀取的
                        start = start+end;
                        end = start -end;
                        start = start-end;
                      }
              String select = edit.getText().toString().substring(start,end);
              clipboard.setText(select);//放到剪貼板

           }           

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章