Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the selected state of an image button with xml

I have an image button as defined below.

<ImageButton 
    android:text="Play"
    android:src="@drawable/playpause"
    android:background="@drawable/opaque" 
    android:gravity="center_horizontal"
    android:id="@+id/player_ctrl_btn"
    android:layout_width="fill_parent" 
    android:padding="0px"
    android:layout_height="wrap_content" />

I want to set the default state of the button to be selected. So in code I would say:

playBtn.setSelected(true);

Is it possible to do this in xml?

like image 249
Jay Askren Avatar asked Feb 10 '10 13:02

Jay Askren


People also ask

How to set image on Button in android XML?

Save the XML file in your project res/drawable/ folder and then reference it as a drawable for the source of your ImageButton (in the android:src attribute). Android will automatically change the image based on the state of the button and the corresponding images defined in the XML.

Which attribute is used to set an image to ImageButton?

Essential image input features The src attribute is used to specify the path to the image you want to display in the button.

How to set Button shape in android studio?

We can set custom shapes on our button using the xml tag <shape> . These xml files are created in the drawable folder too. shape can be used inside selectors . The shape can be set to rectangle (default), oval , ring , line .


1 Answers

It doesn't look like you can -- sorry!

like image 73
CommonsWare Avatar answered Nov 15 '22 19:11

CommonsWare