2013-03-18 155 views

回答

1

我認爲OnFocusChangeListener可能是你正確的選擇。

editText.setOnFocusChangeListener(new OnFocusChangeListener() { 

    @Override 
    public void onFocusChange(View v, boolean hasFocus) { 
     // view/hide ImageView 
    } 
}); 
+3

它工作正常。但我面臨另一個問題。通過按Back鍵,隱藏鍵盤,EditText不會失去焦點,所以ImageViw仍然是Hiden。有沒有一些傾聽鍵盤的傾聽者? – Procurares 2013-03-18 21:10:20

+0

@Procurares我很高興你喜歡它!如果它對你有幫助,請注意/接受答案。是的,這是可能的。閱讀該鏈接瞭解如何:http://stackoverflow.com/questions/4312319/howto-capture-the-virtual-keyboard-show-hide-event-in-android – poitroae 2013-03-19 16:46:21

1
edit_Text.setOnFocusChangeListener(new OnFocusChangeListener() { 
@Override 
public void onFocusChange(View v, boolean hasFocus) { 
    if(hasFocus){ 
     Toast.makeText(getApplicationContext(), "got the focus", Toast.LENGTH_LONG).show(); 
      // Hide your ImageView 
       iv.setVisibility(View.GONE); // (make the view gone) 
    }else 
     Toast.makeText(getApplicationContext(), "lost the focus", Toast.LENGTH_LONG).show(); 
      // Show your ImageView 
       iv.setVisibility(View.VISIBLE); 
    } 
}); 
相關問題