久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

android:如何從觸摸事件中獲取文本位置

android: How to get text position from touch event(android:如何從觸摸事件中獲取文本位置)
本文介紹了android:如何從觸摸事件中獲取文本位置的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我想實現一個自定義文本界面,觸摸+拖動選擇文本并且鍵盤不被抬起,這與長按打開 CCP 菜單和鍵盤的默認行為形成對比.我的理解表明我需要這種方法:

I'm wanting to implement a custom text interface, with touch+drag selecting text and the keyboard not being raised, in contrast to the default behavior of a long-click bringing up the CCP menu and the keyboard. My understanding suggests I need this approach:

onTouchEvent(event){
  case touch_down:
    get START text position

  case drag
    get END text position
    set selection range from START to END
}

我已經了解了所有關于 getSelectStart() 和設置范圍等的各種方法,但我找不到如何根據觸摸事件 getX() 和 getY() 獲取文本位置.有沒有辦法做到這一點?我已經在其他辦公應用中看到了我想要的行為.

I've found out all about getSelectStart() and various methods to setting a range and such, but I cannot find how to get the text position based on a touch event getX() and getY(). Is there any way to do this? I've seen the behaviour I want in other office apps.

另外,在手動請求之前,我將如何阻止鍵盤出現?

Also, how would I stop the keyboard appearing until manually requested?

推薦答案

"mText.setInputType(InputType.TYPE_NULL)" 在 Android 3.0 及以上版本下會抑制軟鍵盤,但也會禁用 EditText 框中閃爍的光標.我編寫了一個 onTouchListener 并返回 true 以禁用鍵盤,然后必須從運動事件中獲取觸摸位置以將光標設置到正確的位置.您可以在 ACTION_MOVE 運動事件上??使用它來選擇要拖動的文本.

"mText.setInputType(InputType.TYPE_NULL)" will suppress the soft keyboard but it also disables the blinking cursor in an EditText box under Android 3.0 and above. I coded an onTouchListener and returned true to disable the keyboard and then had to get the touch position from the motion event to set the cursor to the correct spot. You might be able to use this on an ACTION_MOVE motion event to select text for dragging.

這是我使用的代碼:

  mText = (EditText) findViewById(R.id.editText1);
  OnTouchListener otl = new OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
      switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
          Layout layout = ((EditText) v).getLayout();
          float x = event.getX() + mText.getScrollX();
          int offset = layout.getOffsetForHorizontal(0, x);
          if(offset>0)
              if(x>layout.getLineMax(0))
                  mText.setSelection(offset);     // touch was at end of text
              else
                  mText.setSelection(offset - 1);
          break;
          }
      return true;
      }
  };
  mText.setOnTouchListener(otl);

這篇關于android:如何從觸摸事件中獲取文本位置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 亚州影院 | 欧美老少妇一级特黄一片 | 成人亚洲视频 | 国产96色在线 | 国产成人综合久久 | 成人精品一区二区三区中文字幕 | 韩日有码 | 国产成人精品免高潮在线观看 | 99re视频在线观看 | 国产精品自产拍在线观看蜜 | 欧美 日韩 国产 成人 在线 | www在线视频 | 欧美精品一区二区三区四区五区 | 日韩成人在线电影 | 欧美一级大片免费观看 | 国产黄色大片在线观看 | 国产精品视频一二三区 | 日韩精品成人网 | 国产一区二区激情视频 | 国产精品96久久久久久 | 国产精品毛片 | 97视频在线观看免费 | 在线看片福利 | 久久精品综合网 | 国产亚洲精品精品国产亚洲综合 | 中文字幕av在线 | 久久蜜桃av | 欧洲一级视频 | 中文字幕亚洲精品 | 一区二区成人 | 99精品视频一区二区三区 | 亚州精品天堂中文字幕 | 国产成人精品a视频 | 国产成人在线视频 | 久久婷婷香蕉热狠狠综合 | 羞羞视频网站 | 久久久精品综合 | 亚洲精品视频免费观看 | 色接久久 | 一区二区三区av | 亚洲精彩视频在线观看 |