底部工作表按钮自定义样式不起作用

问题描述

在我的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>

应用所有这些代码后,我无法实现所需的功能。 我想要的设计是:

button design I am looking for

以及我得到的

button design I am getting now

如何在底部对话框的按钮上实现我的自定义设计?

解决方法

您可以使用简单的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="..."/>

enter image description here

,

例如,您可以为按钮使用自定义绘图。

<html lang="en">
<canvas style="inset: 0px; pointer-events: none; position: fixed; z-index: 1000000000;" width="1920" height="514"></canvas>
<head>
...

输出将是类似的

enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...