2017-09-14 7 views
-1

私は、9パッチの背景を持つEditTextを持っています:
enter image description here
検索アイコンをクリック可能にすることはできますか?
ありがとうございます!EditTextの一部をクリック可能にしますか?

+0

いいえ、そうではありません。編集テキストは、9パッチバックグラウンドのどの部分が検索アイコンであるかをどのように知っていますか? –

答えて

2

boolean onTouch(View v, MotionEvent event)を無効にすると可能でしょう。しかし実際にはEditTextの右側に検索アイコンのあるImageViewを入れて、ImageViewのクリックを実装すれば、もっと簡単に時間がかかると思います。

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <EditText 
     android:layout_toLeftOf="@id/search" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 
    <ImageView 
     android:id="@+id/search" 
     android:layout_alignParentRight="true" 
     android:layout_width="wrap_content" 
     android:src="@android:drawable/ic_search_category_default" 
     android:layout_height="wrap_content" /> 
</RelativeLayout> 
+0

onTouchの問題は、どの領域を数えるべきかを知り、それをテキストに重ね合わせないことです。この正解はこれです。 –

+0

テキストが画像を覆わないようにするために、常に右側のパディングを追加することはできますが、それでも私はお勧めのパターンではありません:) – Jon

+0

ありがとう、@GabeSechanはアイコンの一部だけをクリック可能にすることはできません(これは9パッチ画像のうち、非スケーラブルな部分です)? – hereForLearing

関連する問題