Material Slider OnSliderTouchListener's methods can only be called from within the same library group [closed]
Asked Answered
N

2

8

Implementing BaseOnSliderTouchListener's onStartTrackingTouch and onStopTrackingTouch (documentation) give the lint the following error message :

Error: BaseOnSliderTouchListener.onStartTrackingTouch can only be called from within the same library group (referenced groupId=com.google.android.material from groupId=your-group-id) [RestrictedApi]

Nabors answered 27/1, 2022 at 3:57 Comment(0)
A
12

I had the same issue. The workaround with @SuppressLint("RestrictedApi") works.

The root cause is that the BaseOnSliderTouchListener class has a library restricted scope and the methods exposed there are not overridden in OnSliderTouchListener.

The issue is tracked in the material-components library here: https://github.com/material-components/material-components-android/issues/2493

It has been fixed in the 1.6.0-alpha02 release of material-components.

Audie answered 2/2, 2022 at 9:14 Comment(0)
N
6

Temporary solution:

Add @SuppressLint("RestrictedApi") annotation.

Example:

    slider.addOnSliderTouchListener(object : Slider.OnSliderTouchListener {
        @SuppressLint("RestrictedApi")
        override fun onStartTrackingTouch(slider: Slider) {
             [...]
        }

        @SuppressLint("RestrictedApi")
        override fun onStopTrackingTouch(slider: Slider) {
          [...]
        }
    })
Nabors answered 27/1, 2022 at 3:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.