2015-08-14 49 views
0

當我將焦點放在EditText上時,需要將我的圖標從EditText的右側移動到左側(動畫)。此外,我需要將另一個圖標放在可繪製的右側。在EditText焦點上從右向左移動drawElement

enter image description here

這裏是我的XML佈局到目前爲止

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:descendantFocusability="beforeDescendants" 
    android:focusableInTouchMode="true" 
    tools:context="com.example.SearchActivity"> 

    <EditText 
     android:id="@+id/barSearch" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="0dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="20dp" 
     android:background="@drawable/search_bar" 
     android:drawableRight="@drawable/ic_search_white" 
     android:drawingCacheQuality="high" 
     android:ems="10" 
     android:gravity="start" 
     android:lines="1" 
     android:maxLines="1" 
     android:paddingBottom="10dp" 
     android:paddingLeft="15dp" 
     android:paddingRight="15dp" 
     android:paddingTop="10dp" 
     android:singleLine="true" 
     android:focusable="true" android:focusableInTouchMode="true" 
     android:imeOptions="actionSearch" 
     android:textColor="@color/white" 
     android:textStyle="bold" /> 

此外,當我開始活動,EditText上是失焦,如果我點擊它,它得到的焦點,但是當我點擊somwere else或點擊後退按鈕我想放鬆焦點。如果我點擊返回按鈕,鍵盤desapears但EditText保持焦點。

有沒有人知道什麼是實現這一目標的正確方法。

+0

要更新您的EditText的圖標我會建議使用setCompoundDrawablesWithIntrinsicBounds()方法。但變化立即發生。 –

回答

0

試試這個.....

// Set drawables for left, top, right, and bottom - send 0 for nothing 

editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.drawableRight, 0); 
相關問題