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?
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.
Essential image input features The src attribute is used to specify the path to the image you want to display in the button.
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 .
It doesn't look like you can -- sorry!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With