Android 底部板材按钮自定义样式不起作用
在我的Android 底部板材按钮自定义样式不起作用,android,android-button,android-styles,android-dialogfragment,android-bottomsheetdialog,Android,Android Button,Android Styles,Android Dialogfragment,Android Bottomsheetdialog,在我的BottomSheetDialogFragment中,我有一个按钮,我想让这个按钮的背景用灰色边框圆角 这是我的圆形背景可绘制的“rounded\u tranparent\u background.xml”: 我将此背景应用于我的底部工作表按钮 下面是底部图纸布局代码: <?xml version="1.0" encoding="utf-8"?> <layout xmlns:app="http://schemas.an
BottomSheetDialogFragmen
t中,我有一个按钮,我想让这个按钮的背景用灰色边框圆角
这是我的圆形背景可绘制的“rounded\u tranparent\u background.xml”:
我将此背景应用于我的底部工作表按钮
下面是底部图纸布局代码:
<?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>
我得到了什么
如何在“底部图纸”对话框中的按钮上实现自定义设计?例如,您可以使用自定义可绘制按钮
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:ignore="ResourceName">
<solid android:color="@color/inside_color" />
<stroke
android:color="@color/border_color"
android:width="3px" />
<corners android:radius="16dp" />
</shape>
输出将是这样的
例如,您可以为按钮使用自定义可绘制功能
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:ignore="ResourceName">
<solid android:color="@color/inside_color" />
<stroke
android:color="@color/border_color"
android:width="3px" />
<corners android:radius="16dp" />
</shape>
输出将是这样的
您可以使用一个简单的材质按钮
:
<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="..."/>
您可以使用一个简单的材质按钮
:
<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="..."/>
为什么要使用。相反,您应该只使用topLeft和topRight。此外,您还可以使用自定义UI进行“关闭”。使用ViewObject下方的视图(关闭)。背景为黑色,与上面的示例类似。您是否使用材质组件库?为什么使用。相反,您应该只使用topLeft和topRight。此外,您还可以使用自定义UI进行“关闭”。使用ViewObject下方的视图(关闭)。给背景黑色,它将类似于上面的例子你在使用材料组件库吗?如果你检查我的问题,这部分代码已经存在。我想问题出在这个片段的背后。不幸的是,兄弟,你没有写这个代码或者你没有上传它。我没见过你的拖鞋。相反,您使用的是style=“btnFollowUnFollow”。你应该使用其中一个。他们两个都不是。它不像你所说的那样有效。将样式更改为drawable然后按钮将更改。检查问题的第一部分,我不知道我的代码与您的代码有何不同……如果您检查我的问题,这部分代码已经存在。我想问题出在这个片段的背后。不幸的是,兄弟,你没有写这个代码或者你没有上传它。我没见过你的拖鞋。相反,您使用的是style=“btnFollowUnFollow”。你应该使用其中一个。他们两个都不是。它不像你所说的那样有效。将样式更改为drawable,然后按钮将更改。检查问题的第一部分,我不知道我的代码与您的代码有何不同。。。。。。