hi i have to realize this layout . it has this layout.
I could try to use the icons as imagebuttons but the active state of a button is somewhat like this one !
How should i proceed with this ?
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 .
In android, we have a different type of buttons available to use based on our requirements, those are ImageButton, ToggleButton, RadioButton. In android, we can create a Button control in two ways either in the XML layout file or create it in the Activity file programmatically.
You should use selector
as follows:
Prepare 2 images for button states, and put it into res/drawable
folder.
button_normal_green.png – Default image button.
button_pressed_yellow.png – Display when button is pressed.
Now, create a new XML file in “res/drawable/” folder, in whatever name you want, in this case, we just give a name as “new_button.xml“. This file defined which button state is belong to which image.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_pressed_yellow" android:state_pressed="true" />
<item android:drawable="@drawable/button_normal_green" />
</selector>
3.set background to button
<ImageButton
android:id="@+id/imageButtonSelector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/new_button" />
Have a look at Complete Example
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