Come posso nascondere ImageView
quando viene visualizzata la tastiera (dopo aver premuto su alcuni EditText
). E poi mostrare questo ImageView
quando la tastiera viene chiusa?Nascondi visualizzazione immagine quando viene visualizzata la tastiera e mostra quando scompare la tastiera
5
A
risposta
1
Penso che OnFocusChangeListener
potrebbe essere la cosa giusta per voi.
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// view/hide ImageView
}
});
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);
}
});
funziona benissimo. Ma ho affrontato un altro problema. Premendo il tasto Indietro, per nascondere la tastiera, 'EditText' non perde la messa a fuoco, quindi ImageViw è ancora Hiden. C'è un ascoltatore per il rifiuto della tastiera? – Procurares
@Procurares Sono contento che ti piaccia! Si prega di votare/accettare la risposta, se ti ha aiutato. Sì, è possibile. Leggi su questo link per scoprire come: http://stackoverflow.com/questions/4312319/howto-capture-the-virtual-keyboard-show-hide-event-in-android – poitroae