Reputation: 291
I'm a designer and about to do some light redesign of the standard components on Android. Right now I'm trying to figure out how button states works. According to Material Design guidelines the standard buttons, Floating action button, Raised and Flat buttons, have four states: Normal, Focus, Pressed and Disabled.
Upvotes: 2
Views: 196
Reputation: 5636
No system does not take color by itself if you provide color for Normal State. For your second question, if you want to give shape then you can create a selector as specified by @Surace in drawable folder, but if you wish to only change color based on state then create a selector in
res/color
directory.
Rest of the things remain same, as you implement in selector created in drawable folder.
Upvotes: 1
Reputation: 1188
You can customize the button state color by using selector .
Suppose following is button_state_color.xml file in your drawable directory
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:color="hex_color"
android:state_pressed=["true" | "false"]
android:state_focused=["true" | "false"]
android:state_selected=["true" | "false"]
android:state_checkable=["true" | "false"]
android:state_checked=["true" | "false"]
android:state_enabled=["true" | "false"]
android:state_window_focused=["true" | "false"] />
</selector>
Use it in your button like this
<Button
...
android:background="@drawable/button_state_color.xml"
...
/>
Upvotes: 3