2013-01-12 40 views
0

我有一個自定義的屏幕後退按鈕,一旦用戶點擊我的屏幕的EditText後,我想將其更改爲「隱藏鍵盤」。我找到了this question的一些很好的代碼,關於檢測鍵盤是否打開(查看Reuben Scratton的舊答案,瞭解我所做的)。我在java文件步驟:Android - 在鍵盤打開後更改按鈕

@Override 
public void onSoftKeyboardShown(boolean isShowing) { 
    // do whatever you need to do here 
} 

我怎麼會在這裏輸入代碼後退按鈕來改變它的形象一旦鍵盤打開?

這裏是我的後退按鈕當前的代碼:我想將其更改爲

<ImageButton 
     android:id="@+id/back" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@null" 
     android:contentDescription="Back" 
     android:scaleType="fitStart" 
     android:src="@drawable/back_bar" /> 

<ImageButton 
     android:id="@+id/back" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@null" 
     android:contentDescription="Back" 
     android:scaleType="fitStart" 
     android:src="@drawable/hide_keyboard" /> 

這裏是我想要的情況下,做一個像我沒有任何意義! image http://i47.tinypic.com/11vqvew.png

回答

0

你可以使用:

ImageButton backButton = (ImageButton)findViewById(R.id.back); 
backButton.setImageResource(R.drawable.hide_keyboard); 

onSoftKeyboardShown方法