我有几个按钮,我需要椭圆形边框。
所以我把它放在capsule_border.xml中
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="9999dp"/>
<stroke
android:width="1px"
android:color="@color/border_gray" />
</shape>
我会用android:background="@drawable/capsule_border.xml
我需要它的地方。
现在,我想要一个具有椭圆形边框的按钮,而且还有一个android:background="?selectableItemBackground"
用于视觉反馈。
我尝试使用带有 selectableItembackground 的父布局和带有capsule_border 的按钮。但突出显示的可点击区域似乎是整个正方形。而不仅仅是胶囊边界内的区域。
有什么办法可以让 selectableItemBackground 不高度占据视图的整个矩形,而只在我绘制的边框内?
Having 圆角.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/transparent"/>
<corners android:radius="15dp" />
<stroke
android:width="1px"
android:color="#000000" />
</shape>
And my_ripple.xml:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorControlHighlight">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#000000" />
<corners android:radius="15dp" />
</shape>
</item>
<item android:drawable="@drawable/round_corners" />
</ripple>
和按钮:
<Button
android:background="@drawable/my_ripple"
... />
会导致这样的结果:
See this http://michaelevans.org/blog/2015/05/07/android-ripples-with-rounded-corners/文章。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)