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
}
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.
Snakbar 是 final 类,它不是继承的,但您可以修改 Snakbar 的视图。
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.