[Slider] Material theme needs to be explicitly defined to render Slider in preview mode
See original GitHub issueDescription:
Without explicitly specifying a theme, the Slider class fails to instantiate in the layout preview mode. The activity inherits from AppTheme, AppTheme inherits from Theme.MaterialComponents.Light.NoActionBar
.
It builds and runs fine on the device, just that in the preview mode it never gets rendered.
java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant). at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
Expected behavior: Renders in preview mode, doesn’t require extra theme
Source code:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<com.google.android.material.slider.Slider
android:id="@+id/slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:value="20"
android:valueFrom="5.0"
android:valueTo="100.0"
app:labelBehavior="gone"
app:trackColorActive="@color/icon_primary"
app:trackColorInactive="@color/ui_dark"/>
To fix this, I had to add android:theme="@style/AppTheme"
to the xml.
Android API version: 29
Material Library version: 1.2.0-alpha05
Device: API28 Samsung A70
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Sliders – Material Design 3
Sliders allow users to make selections from a range of values. ... When interacting with a slider, changes should be reflected back to...
Read more >Designing The Perfect Slider - Smashing Magazine
But first, we need to figure out when a slider makes sense in the first ... or preview or detail view, it should...
Read more >Sliders — Material Component For Android | Analytics Vidhya
Sliders used to view and select a value or range from the given slider bar.They're mainly used for adjusting settings such as volume...
Read more >androidx.compose.material - Android Developers
Material Design defines the qualities that can be expressed by UI regions, ... Represents the colors used by a Slider and its parts...
Read more >Sliders - Selection and input - Human Interface Guidelines
A linear slider often includes supplementary icons that illustrate the meaning of the minimum and maximum values. In a circular slider, the thumb...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looks like it! I was able to repro the issue in 4.0 Beta 3. I can ask the team if it’s possible to backport the fix to 3.6 and 4.0. Thanks for investigating!
Just tried it out with the newest Canary version and it works just fine. So it’s probably some Android Studio problem then which was already solved?
Android Studio 4.1 Canary 4 Build #AI-193.6494.35.41.6325121, built on March 23, 2020 Runtime version: 1.8.0_242-release-1644-b3-6222593 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o macOS 10.14.6 GC: ParNew, ConcurrentMarkSweep Memory: 1979M Cores: 12 Registry: ide.new.welcome.screen.force=true Non-Bundled Plugins: org.jetbrains.kotlin