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

處理 EditText 中可繪制對象的點擊事件

Handling click events on a drawable within an EditText(處理 EditText 中可繪制對象的點擊事件)
本文介紹了處理 EditText 中可繪制對象的點擊事件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我使用以下 XML 在 EditText 小部件中添加了文本右側的圖像:

I have added an image right of the text in an EditText widget, using the following XML:

<EditText
  android:id="@+id/txtsearch"
  ...
  android:layout_gravity="center_vertical"
  android:background="@layout/shape"
  android:hint="Enter place,city,state"
  android:drawableRight="@drawable/cross" />

但我想在單擊嵌入圖像時清除 EditText.我該怎么做?

But I want to clear the EditText when the embedded image is clicked. How can I do this?

推薦答案

其實你不需要擴展任何類.假設我有一個帶有 drawableRight 的 EditText editComment

Actually you don't need to extend any class. Let's say I have an EditText editComment with a drawableRight

editComment.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        final int DRAWABLE_LEFT = 0;
        final int DRAWABLE_TOP = 1;
        final int DRAWABLE_RIGHT = 2;
        final int DRAWABLE_BOTTOM = 3;

        if(event.getAction() == MotionEvent.ACTION_UP) {
            if(event.getRawX() >= (editComment.getRight() - editComment.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                // your action here

                return true;
            }
        }
        return false;
    }
});

我們 getRawX() 因為我們想要獲取屏幕上觸摸的實際位置,而不是相對于父級.

we getRawX() because we want to get the actual position of touch on screen, not relative to parent.

左鍵點擊

if(event.getRawX() <= (editComment.getCompoundDrawables()[DRAWABLE_LEFT].getBounds().width())) 

這篇關于處理 EditText 中可繪制對象的點擊事件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本選擇處理程序單擊事件上的粘貼/替換菜單彈出)
Multiline EditText with Done SoftInput Action Label on 2.3(2.3 上帶有完成 SoftInput 操作標簽的多行 EditText)
How to detect the swipe left or Right in Android?(如何在 Android 中檢測向左或向右滑動?)
Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋轉對話框解除)
How do I handle ImeOptions#39; done button click?(如何處理 ImeOptions 的完成按鈕點擊?)
How do you set EditText to only accept numeric values in Android?(您如何將 EditText 設置為僅接受 Android 中的數值?)
主站蜘蛛池模板: 日韩精品一区二区三区在线观看 | 亚洲精品一区二区三区蜜桃久 | 亚洲一二三在线 | 香蕉久久久 | 欧产日产国产精品视频 | 黄色免费观看网站 | 精品1区2区 | 一级毛片网 | 久久久久国产 | 国产精品久久久久久婷婷天堂 | 欧美激情在线精品一区二区三区 | 一区二区三区高清在线观看 | 狠狠操你 | 永久免费视频 | 99精品网 | 中文字幕精品一区二区三区在线 | 黄色网页在线 | 日韩在线 | 国产成人麻豆免费观看 | 精品视频免费 | 久久激情网 | 国产精品视频一区二区三区四蜜臂 | 中文字幕在线欧美 | 日韩中文电影 | 国产精品国产亚洲精品看不卡15 | 在线免费小视频 | 午夜在线 | h视频在线观看免费 | 阿v视频在线观看 | 国产ts人妖系列高潮 | 国产一区二区在线免费视频 | 国产精品久久久久久久岛一牛影视 | 久久久久久国产精品 | 日韩高清中文字幕 | 九九九国产 | 亚洲国产一区二区三区 | 精彩视频一区二区三区 | 91精品国产色综合久久 | 欧美日韩视频 | 精品久久久久国产 | 亚洲精品视频在线 |