我正在尝试创建一个 outlined Material Components button ,但是除了描边之外,我还需要它有一个半透明的背景。
到目前为止,这是我的 XML 代码:
<android.support.design.button.MaterialButton
android:id="@+id/foo"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:backgroundTint="#CFFF"
app:strokeColor="@color/colorAccent"
app:strokeWidth="2dp" />
这就是它的样子:
问题是一些背景在按钮周围的笔划之外可见(笔划宽度越大,出现的白色像素越多)。
例如,这是一个 5dp
笔画:
有没有办法解决这个问题,更好的设置背景颜色的方法,或者其他什么?
最佳答案
只需使用 Widget.MaterialComponents.Button.OutlinedButton
样式:
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
app:strokeWidth="2dp"
app:strokeColor="@color/colorAccent"
app:backgroundTint="#3ad64f"
.../>
关于android - 为带轮廓的 Material Components 按钮的背景着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50571221/