0

I want to create a class which extends Snackbar but I couldn't find the constructor in the Google documentation. How should I add the constructor to the class:

import com.google.android.material.snackbar.Snackbar

class MySnackbar : Snackbar { 
    // Error: need a constructor
}
Payam Roozbahani
  • 1,225
  • 15
  • 27

3 Answers3

4

SnackBar is final class and thus cannot be inherited. One way is to access SnackBar's view (snackbar.getView()) and modify the view as per your need.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Deepak Senapati
  • 1,103
  • 2
  • 11
  • 30
0

Snakbar is a final class and its not inherited but you can modify the view of snackbar.

Avinash
  • 867
  • 4
  • 11
-1

You can create secondary constructor, Use below code for Kotlin.

class MyCustomSeekBar : AppCompatSeekBar {
    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
}

Hope it helps you.