androidmaterial-designmaterial-components-androidandroid-slider

How to change slider font style?


I am using the material slider, I want to change the custom font slider's toast

can anyone guide me how to change the slider's font style?

My code:

  <com.google.android.material.slider.Slider
                         android:theme="@style/ThemeOverlay.PrimaryPalette.Red"
                         style="@style/Widget.App.Slider"

                         android:id="@+id/sliderRadius"
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         android:stepSize="1"
                         android:valueFrom="0"
                         android:valueTo="20" />



<style name="Widget.App.Slider" parent="Widget.MaterialComponents.Slider">
        <item name="android:textAppearance">@style/TextAppearance.App.Tooltip</item>
    </style>
    <style name="TextAppearance.App.Tooltip" parent="TextAppearance.MaterialComponents.Tooltip">
        <item name="android:textColor">@color/purple_500</item>
        <item name="fontFamily">@font/josefin_sans_semibold</item>
        <item name="android:fontFamily">@font/josefin_sans_semibold</item>
    </style>
 <style name="ThemeOverlay.PrimaryPalette.Red" parent="">
        <item name="colorPrimary">#e53935</item>
        <item name="colorPrimaryDark">#ab000d</item>
      <!--  <item name="android:textAppearance">@style/TextAppearance.App.Tooltip</item>-->
 </style>

Slider

implementation 'com.google.android.material:material:1.3.0'


Solution

  • You can use something like:

           <com.google.android.material.slider.Slider
               style="@style/App.Slider"/>
    

    with:

    <style name="App.Slider" parent="@style/Widget.MaterialComponents.Slider">
        <item name="labelStyle">@style/App.Tooltip</item>
    </style>
    
    <style name="App.Tooltip" parent="Widget.MaterialComponents.Tooltip">
        <!-- background color of the Tooltip -->
        <item name="backgroundTint">@color/...</item>
        <!-- textAppearance of the Tooltip -->
        <item name="android:textAppearance">@style/TextAppearance.App.Tooltip</item>
    </style>
    
    <style name="TextAppearance.App.Tooltip" parent="TextAppearance.MaterialComponents.Tooltip">
        <item name="android:textColor">@color/....</item>
    </style>
    

    enter image description here