How to create button shadow in android material design style -
new material design guidelines introduce elevated buttons dropping nice shadow. according preview sdk documentation there elevation
attribute available in new sdk. however, there way achieve similar effect now?
this worked me.
layout having button
<button xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="@dimen/button_size" android:layout_height="@dimen/button_size" android:background="@drawable/circular_button_ripple_selector" android:textappearance="?android:textappearancelarge" android:textcolor="@color/button_text_selector" android:statelistanimator="@anim/button_elevation"/>
drawble/button_selector.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:drawable="@drawable/button_selected"/> <item android:state_pressed="true" android:drawable="@drawable/button_pressed"/> <item android:drawable="@drawable/button"/> </selector>
anim/button_elevation.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="true" android:state_pressed="true"> <objectanimator android:duration="@android:integer/config_shortanimtime" android:propertyname="translationz" android:valuefrom="2dip" android:valueto="4dip" android:valuetype="floattype" /> </item> <item> <objectanimator android:duration="@android:integer/config_shortanimtime" android:propertyname="translationz" android:valuefrom="4dip" android:valueto="2dip" android:valuetype="floattype" /> </item> </selector>
if have button in rectangular shape done here. if have circular or oval shaped button looking like,
to remove corners circular or oval shaped button add code .java
file.
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); ........... int buttonsize = (int) getresources().getdimension(r.dimen.button_size); outline circularoutline = new outline(); circularoutline.setoval(0, 0, buttonsize, buttonsize); (int = 0; < max_buttons; i++) { button button = ...... ....... button.setoutline(circularoutline); ........ } ..... }
angular shape removed!! now, like
Comments
Post a Comment