解决方法
这对我有用.
布局有按钮
<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>
动画/ 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>
如果你有一个长方形的按钮,那么你就完成了.但如果你有圆形或椭圆形按钮那么它看起来像,
要从圆形或椭圆形按钮中删除角,请将此代码添加到.java文件中.
@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,buttonSize,buttonSize); for (int i = 0; i < MAX_BUTTONS; i++) { Button button = ...... ....... button.setOutline(circularOutline); ........ } ..... }
角形形状删除!!现在,它看起来就像