问题描述
在我的BottomSheetDialogFragmen
t中,我有一个按钮,我想使此按钮的背景以灰色边框四舍五入。
这是我的四舍五入的背景可绘制对象“ rounded_tranparent_background.xml”:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<solid android:color="#FFF" />
<stroke
android:width="1dp"
android:color="#8A8383" />
<corners
android:bottomLefTradius="10dp"
android:bottomrighTradius="10dp"
android:topLefTradius="10dp"
android:topRighTradius="10dp" />
</shape>
我将此背景应用于底页按钮。
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnFollowUnfollow"
android:background="@drawable/rounded_tranparent_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/avenir_next_ltpro_medium"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Unfollow"
android:textColor="@color/colorGreyDark"
app:layout_constraintBaseline_toBaselineOf="@+id/tvTitle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.71"
app:layout_constraintStart_toEndOf="@+id/tvTitle" />
//...other code...
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
这是我的底页对话框样式
<style name="AppBottomSheetDialogTheme"
parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:windowTranslucentStatus">true</item>
<item name="colorPrimary">@color/colorBlue</item>
<item name="colorPrimaryDark">@color/colorBlueDark</item>
<item name="colorAccent">@android:color/transparent</item>
</style>
应用所有这些代码后,我无法实现所需的功能。 我想要的设计是:
解决方法
您可以使用简单的MaterialButton
:
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cornerRadius="10dp"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:textColor="..."
app:strokeColor="..."/>
,
例如,您可以为按钮使用自定义绘图。
<html lang="en">
<canvas style="inset: 0px; pointer-events: none; position: fixed; z-index: 1000000000;" width="1920" height="514"></canvas>
<head>
...
输出将是类似的