1

I'm trying to use a MaterialButtonToggleGroup inside my BottomSheetDialog. However the style for the button is being overriden by the current theme I'm using for the BottomSheet

In a regular fragment:

Using the attribute

style="?attr/materialButtonOutlinedStyle"

I have this blue outline on my Material Button inside my ToggleGroup

<com.google.android.material.button.MaterialButtonToggleGroup
        android:id="@+id/toggle_group"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:checkedButton="@+id/btnOne"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="16dp"
        app:selectionRequired="true"
        app:singleSelection="true">

        <com.google.android.material.button.MaterialButton
            android:id="@+id/btnOne"
            style="?attr/materialButtonOutlinedStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 1"
            android:minHeight="0dp"
            android:textSize="12sp"/>

        <com.google.android.material.button.MaterialButton
            android:id="@+id/btnTwo"
            style="?attr/materialButtonOutlinedStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minHeight="0dp"
            android:text="Button 2"
            android:textSize="12sp"/>


    </com.google.android.material.button.MaterialButtonToggleGroup>

enter image description here

But when using it inside my BottomSheet I get this:

enter image description here

The theme for bottom sheet I'm using:

<style name="Theme.TestApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
        ...
        
        <item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
</style>
    <style name="AppBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
        <item name="bottomSheetStyle">@style/BottomSheetRoundedCorners</item>
    </style>

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

How can I keep the style

style="?attr/materialButtonOutlinedStyle"

for the MaterialButton while using the BottomSheet's theme?

Edit:______________________________

I've tried adding

<item name="materialButtonStyle">@style/Widget.MaterialComponents.Button.OutlinedButton</item> to my BottomSheet's theme but it doesn't do anything.

<style name="AppBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
        <item name="bottomSheetStyle">@style/BottomSheetRoundedCorners</item>
        <item name="materialButtonStyle">@style/Widget.MaterialComponents.Button.OutlinedButton</item>
    </style>

Have also tried it with

<item name="materialButtonStyle">?attr/materialButtonOutlinedStyle</item>

DIRTY DAVE
  • 2,523
  • 2
  • 20
  • 83

1 Answers1

2

you can use this theme:

<style name="BottomSheet" parent="Theme.MaterialComponents.DayNight.BottomSheetDialog"/>

<style name="Theme.TestApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    ...
    
    <item name="bottomSheetDialogTheme">@style/BottomSheet</item>

DO NOT USE THEME.DESIGN.LIGHT

OneDev
  • 557
  • 3
  • 14
  • If I use ```DayNight``` it doesn't use my primary color but uses the secondary color – DIRTY DAVE Jan 23 '22 at 06:49
  • I test it, it works, it uses primary color if you declare this style in your both day and night theme. maybe you give a custom color/style to your button – OneDev Jan 23 '22 at 06:56
  • It's giving me the color purple. I don't have the color purple anywhere inside my app... https://i.imgur.com/qdc8pLm.png I have tried uninstall reinstalling the app I checked both themes, day and night, they both don't have purple – DIRTY DAVE Jan 23 '22 at 07:07
  • can you post your full code for the button and styles? – DIRTY DAVE Jan 23 '22 at 07:15
  • The default color is apparently purple from this answer: https://stackoverflow.com/a/65283532/11110509 but I can't change it. Can't change it to blue with ```android:textColorHighlight="@color/blueColor"``` Doesn't do anything – DIRTY DAVE Jan 23 '22 at 07:26
  • https://stackoverflow.com/a/64239236/11110509 This answer allowed me to remove the default purple color to my blue color. Thanks for your help. – DIRTY DAVE Jan 23 '22 at 07:32