So I'm making an android app that has more than 100 buttons,but you know when you tap a button normally when you don't changed the background or anything it flashes orangish color. However since I've added a background color to my buttons when they're tapped it just goes to the next screen and you can't tell that you've tapped a Button!
Could someone help me please? Sorry if I don't know what those are called:(
Declare in drawables this selector and name it for example: button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true"
android:drawable="@drawable/btnPressed"/>
<item android:drawable="@drawable/btnNormal"></item>
</selector>
android:drawable can be color, image, another drawable... And then you can declare your button as:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button"
/>
If you create your buttons in code you can call method: setBackgroundResource() and pass resource id. Example:
Button button = new Button(this);
button.setBackgroundResource(R.drawable.button);
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
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