0

BottomSheetDialogFragment の角を丸くする必要があったため、背景としてカスタム ドローアブルを適用しました。しかし、カスタム背景を適用した後、BottomSheet のボタンはカスタム背景を受け入れません。白い背景を表示するだけです。backgroundTint は正常に機能し、ボタンの色を変更します。

themes.xml :

<style name="AppBottomSheetDialogTheme"
    parent="Theme.Design.Light.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/AppModalStyle</item>
</style>

<style name="AppModalStyle"
    parent="Widget.Design.BottomSheet.Modal">
    <item name="android:background">@drawable/add_new_bg</item>
</style>

add_new_bg.xml :

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid
        android:color="@color/background"/>
    <corners
        android:topLeftRadius="40dp"
        android:topRightRadius="40dp"/>
</shape>

BottomSheetDialogFragment コード:

@Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(STYLE_NORMAL, R.style.AppBottomSheetDialogTheme);
    }
4

2 に答える 2

2

これを試して :

  1. メインテーマがTheme.AppCompat.Lightの場合:

例 :

<style name="Theme.YourAppName" parent="Theme.AppCompat.Light">
    <!-- Primary brand color. -->
    <!-- Customize your theme here. -->
</style>

あなたのボタンは次のとおりです。

<Button <------ material button type
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/buttonTheme" <---- add this
    android:text="MyButton"/>

これをメインテーマの下のthemes.xmlに追加します

    <style name="buttonTheme" parent="Theme.MaterialComponents.Light">
       <item name="theme">@style/buttonTheme</item>
       <item name="android:textColor">@color/white</item>
       <item name="android:background">@color/black</item>
   </style>
  1. メインテーマが次の場合: Theme.MaterialComponents

例 :

<style name="Theme.RecyclerView" parent="Theme.MaterialComponents.Light">
    <!-- Primary brand color. -->
    <!-- Customize your theme here. -->
</style>

しかし、あなたのボタンの使用:

<androidx.appcompat.widget.AppCompatButton <<<<--- appcompact button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/buttonTheme" 
        android:text="MyButton"/>

それから加えて :

<style name="buttonTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="theme">@style/buttonTheme</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:background">@color/black</item>
</style>

ボタンタイプのテーマは同じタイプでなければなりません。

これがうまくいくかどうか教えてください..そしてそれを支持してください:)

于 2021-02-14T01:06:16.513 に答える