2012-06-28 9 views

Respuesta

25

uso StateListDrawable para seeting selector de código como:

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? ¿Necesito configurar uno dentro de mi diseño? – TalMihr

+0

sí, como su necesidad crear dinámicamente o agregar una vista de imagen a Xml diseño –

+0

¿cómo lo hago de forma dinámica? – TalMihr

3

Puede configurar el botón dibujable de java como

btnSettings.setBackgroundResource(R.drawable.ic_launcher); 
Cuestiones relacionadas