我想要一个带有 backgroundTint
和 corner
半径的 button
:D
这是我定义的样式:
<style xmlns:tools="http://schemas.android.com/tools" name="myButton" parent="Widget.AppCompat.Button.Colored">
<item name="android:background">@drawable/button_light</item>
<item name="android:backgroundTint" tools:targetApi="lollipop">#e0e0e0</item>
</style>
@drawable/button_light
代码:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="15dp" />
<solid android:color="#FAFAFA" />
</shape>
然后我将 @style/myButton
应用于我想要的 button
结果是我有圆角但没有 ripple
效果(backgroundTint
确实不起作用)。
我该如何解决这个问题?
最佳答案
您可以使用图层列表来实现这一点。
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<corners android:radius="15dp" />
<solid android:color="#FAFAFA" />
</shape>
</item>
<!-- Put any image or anything here as the drawable -->
<item android:drawable="?attr/selectableItemBackground"/>
</layer-list>
关于java - 如何有一个带有 backgroundTint 和圆角半径的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52015066/