2012-06-28 8 views

risposta

25

uso StateListDrawable per seeting selettore per codice come:

StateListDrawable states = new StateListDrawable(); 
states.addState(new int[] {android.R.attr.state_pressed}, 
    getResources().getDrawable(R.drawable.pressed)); 
states.addState(new int[] {android.R.attr.state_focused}, 
    getResources().getDrawable(R.drawable.focused)); 
states.addState(new int[] { }, 
    getResources().getDrawable(R.drawable.normal)); 

imageView.setImageDrawable(states); //YOUR IMAGE HERE 
//AND FOR BUTTON 
button.setBackgroundDrawable(states);//FOR BUTTON 
+0

imageView? devo installarne uno nel mio layout? – TalMihr

+0

sì come è necessario creare dinamicamente o aggiungere un layout Imageview a Xml –

+0

come faccio a farlo in modo dinamico? – TalMihr

3

È possibile impostare il tasto drawable da Java come

btnSettings.setBackgroundResource(R.drawable.ic_launcher); 
Problemi correlati