使按钮动画不超过可绘制背景

问题描述 投票:0回答:1

Top button: Not pressed, bottom button pressed

如何使android上的按钮上的“默认”块动画单击以适合所设置的可绘制背景?可绘制背景为按钮提供了圆角。

按钮:

        <Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dip"
    android:layout_marginTop="16dp"
    android:clickable="true"
    android:background="@drawable/setting_button"
    android:foreground="?android:attr/selectableItemBackgroundBorderless"
    android:focusable="true" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:layout_marginTop="16dp"
        android:clickable="true"
        android:background="@drawable/setting_button"
        android:foreground="?android:attr/selectableItemBackgroundBorderless"
        android:focusable="true" />

可绘制设置按钮

<?xml version="1.0" encoding="utf-8"?>
<!--  res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:padding="10dp">
    <solid android:color="@color/colorWhite"/>
    <corners
        android:bottomRightRadius="15dp"
        android:bottomLeftRadius="15dp"
        android:topLeftRadius="15dp"
        android:topRightRadius="15dp"/>
</shape>
android xml android-layout android-button
1个回答
0
投票

解决方案在于RippleDrawable的特殊遮罩层。您可以通过设置为@android:id / mask的android:id值指定遮罩层。https://proandroiddev.com/rippling-rounding-and-android-pies-d5db5f4c2fc1http://michaelevans.org/blog/2015/05/07/android-ripples-with-rounded-corners/

© www.soinside.com 2019 - 2024. All rights reserved.