久久久久久久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問題)
主站蜘蛛池模板: 久久久天堂国产精品女人 | 亚洲小视频在线观看 | 亚色视频 | 午夜亚洲精品 | 国产欧美日韩综合 | 性史性dvd影片农村毛片 | 久久久久国产精品夜夜夜夜夜 | 可以免费看av的网站 | 中文字幕网站 | 1024日韩 | 九九精品在线视频 | 亚洲精选在线观看 | 99中文字幕| 黄色一级影片 | 黑人精品一区二区 | 色综合天天综合网天天狠天天 | 欧美999| 爱爱免费小视频 | 亚洲男人天堂网 | 成人av播放 | 日日夜夜精品 | 色综合视频在线观看 | 国产黄色大片 | 啪啪综合网 | 欧美在线视频一区 | 国产精品一区二区视频 | 国产精品xxx在线观看 | 久操精品视频 | 一区二区免费在线观看 | 欧美在线视频免费观看 | 91狠狠干| 成人免费看片视频 | 久久精品99久久久久久 | 免费看黄色aaaaaa 片 | 国产视频三区 | 精品一区二区三区视频 | 97国产视频 | 美女天天干 | 少妇一级淫片免费看 | 99精品热 | av日韩在线播放 |