Reputation: 1358
I know that I can set the background
of my button
by using a custom drawable
like this:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<gradient
android:startColor="#ffffff"
android:endColor="#ffffff"
android:angle="270" />
</shape>
</item>
<item android:state_focused="true" >
<shape>
<gradient
android:endColor="#ffffff"
android:startColor="#ffffff"
android:angle="270" />
</shape>
</item>
<item>
<shape>
<gradient
android:endColor="#ffffff"
android:startColor="#ffffff"
android:angle="270" />
</shape>
</item>
</selector>
I also know how to set that.
But my real question is: how do I get the look and feel of a default material design button in just a different color, I can't seem to find the default style of it in the Android source.
Upvotes: 1
Views: 569
Reputation: 11873
You can use the style="?android:attr/borderlessButtonStyle"
as a Button's style. This will give you a flat style look and will work on any pre-lollipop devices too.
Reference: http://developer.android.com/reference/android/R.attr.html#borderlessButtonStyle
If you are not interesed in backward compactibility then use can use the Raised Button which has the ripple effect and requires a device running 5.0
<style name="Your.Button" parent="android:style/Widget.Material.Button">
<item name="android:background">@drawable/raised_background</item>
</style>
raised_background.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item android:drawable="@color/button_color"/>
</ripple>
Upvotes: 1