zoukankan      html  css  js  c++  java
  • TextView 选择文字


    final CharSequence edit = text2.getText();
    text2.setCursorVisible(true);

    text2.setOnTouchListener(new OnTouchListener() {

             public boolean onTouch(View v, MotionEvent event) {
               // TODO Auto-generated method stub
                 int sta = 0;
                int end = 0;
               switch (event.getAction()) {

                    case MotionEvent.ACTION_DOWN: {
                    sta = text2.getSelectionStart();

                    return true; 

                     }

                         case MotionEvent.ACTION_MOVE: {
                             text2.setTextColor(Color.RED);
                              SpannableStringBuilder styled = new SpannableStringBuilder(edit);
                              styled.setSpan(new ForegroundColorSpan(Color.BLUE), 1,30,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                              text2.setText(styled);
                              return true;
                             }

                        case MotionEvent.ACTION_UP: {
                            end = text2.getSelectionEnd();
                            CharSequence sel = edit.subSequence(5, 80);
                            text1.append(String.valueOf(end));
                             return true;
                       }
               }
               return true;
           }
       });

  • 相关阅读:
    特斯拉PET钥匙-蓝牙无钥匙
    超声波倒车雷达
    KiCad层次原理图标签和引脚的操作
    Nuget常用命令
    TCP/IP协议入门
    unbuntu(18.04)下体验dotnet core
    c#中的异步
    Git的不完全使用指南
    c#语言特性8.0
    c#语言特性7.x
  • 原文地址:https://www.cnblogs.com/lucktian/p/5520925.html
Copyright © 2011-2022 走看看