mardi 12 mai 2015

Android Custom buttons

Hi have a problem using using custom buttons when I inflate a linear layout with buttons inside.

I am defining a drawable xml as follows to change the background of LinearLayout which acts as a button onclick. It works for all buttons, exept this button. OnClick on the button works but the background does not change as stated by the xml. dynamic_button

<item android:state_pressed="true" android:drawable="@drawable/button_onclick" />
<item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/button" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/button_onclick" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/button_onclick"/>

<item android:drawable="@drawable/button" />

I am inflating a a linearlayout which contains the a button (which is a linear layout with this xml set to change background onClick)

       customView = getLayoutInflater().inflate(R.layout.description_creeps,null);
         ...
       LinearLayout buy = (LinearLayout) customView.findViewById(R.id.btn_ingame_spawn_creeps);
    buy.setBackgroundResource(R.drawable.dynamic_button);
         buy.setFocusable(true);
         buy.setFocusableInTouchMode(true);
        ...
       description_container.removeAllViews();
       description_container.addView(customView);
       description_container.invalidate();

I have no idea why it does not seem to work, I suspect it was the focus issue, but I set focusable to true and it still does not work. Any help would be very usefull.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire