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

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

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

問題描述

限時(shí)送ChatGPT賬號(hào)..

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

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
}

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

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.

另外,在手動(dòng)請求之前,我將如何阻止鍵盤出現(xiàn)?

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

推薦答案

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

"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);

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

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

相關(guān)文檔推薦

Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
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 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 一级做a爰片久久毛片免费看 | 欧美精品在线播放 | 亚洲小视频在线播放 | 一区二区在线观看av | 亚洲国产偷 | 国产xxxx在线 | 中文一区二区视频 | а_天堂中文最新版地址 | 亚洲福利片 | 亚洲男人天堂 | 中文字幕亚洲一区二区三区 | 国产精品久久久久久久久久了 | 国产91久久精品一区二区 | 欧美精品在线一区 | 欧美午夜影院 | 狠狠的干狠狠的操 | 综合久久久 | 婷婷久久网| 91精品国产色综合久久 | 久久久久久黄 | 久久精品国产一区二区三区不卡 | 亚洲激情一区二区三区 | 男女羞羞视频网站 | 黄色欧美在线 | 成人国产在线视频 | 99久久婷婷国产综合精品电影 | 欧美精品成人影院 | 欧美久久免费观看 | 黄色网址在线免费播放 | 国产成人亚洲精品 | 97caoporn国产免费人人 | 日韩在线视频网址 | 日韩欧美一区二区三区免费观看 | 欧美一区二区三区久久精品 | 亚洲天堂免费 | 精品国产三级 | 亚洲va欧美va天堂v国产综合 | 久久久亚洲一区 | 亚洲男人网 | 国产日韩欧美中文字幕 | 日本人爽p大片免费看 |