therealbluepandabear
03/26/2021, 3:27 AMprivate lateinit var trueButton: Button
private lateinit var falseButton: Button
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
trueButton = findViewById(R.id.true_button)
falseButton = findViewById(R.id.false_button)
trueButton.setOnClickListener { makeSnackbar(R.string.correct_toast, it, themeConfig = RandomSnackbarConfiguration()) }
falseButton.setOnClickListener { makeSnackbar(R.string.incorrect_toast, it, themeConfig = RandomSnackbarConfiguration()) }
}
fun makeSnackbar(resId: Int,
viewContext: View,
themeConfig: SnackbarThemeConfiguration = DefaultSnackbarConfiguration()) =
Snackbar.make(viewContext, resId, Snackbar.LENGTH_SHORT)
.setBackgroundTint(themeConfig.backgroundColor)
.setTextColor(themeConfig.textColor).let {
it.setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_SLIDE)
it.show()
}
abstract class SnackbarThemeConfiguration(val backgroundColor: Int, val textColor: Int)
class DefaultSnackbarConfiguration() : SnackbarThemeConfiguration(Color.DKGRAY, Color.WHITE)
class RandomSnackbarConfiguration() : SnackbarThemeConfiguration(
Color.rgb(Random.nextInt(0,256),
Random.nextInt(0, 256),
Random.nextInt(0, 256)),
Color.rgb(Random.nextInt(0,256),
Random.nextInt(0, 256),
Random.nextInt(0, 256)))
}
ephemient
03/26/2021, 3:29 AMtherealbluepandabear
03/26/2021, 3:29 AMBlaž Vantur
03/26/2021, 7:24 AM