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
}

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
  • 250,295
  • 77
  • 670
  • 690
Deepak Senapati
  • 1,083
  • 1
  • 11
  • 30
0

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

Avinash
  • 864
  • 4
  • 10
-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.