You can create customized Snackbar with KSnack. KSnack has 2 view type; KSnack and Minimal KSnack.
- Initialize Minimal KSnack.
MinimalKSnack minimalKSnack = new MinimalKSnack(MainActivity.this);
- Set Features. Styles;
STYLE_DEFAULT
,STYLE_INFO
,STYLE_SUCCESS
,STYLE_ERROR
,STYLE_WARNING
minimalKSnack
.setMessage("This is minimal KSnack !") // message
.setStyle(MinimalKSnackStyle.STYLE_SUCCESS) // style
.setBackgroundColor(R.color.colorGray) // background color
.setBackgrounDrawable(R.drawable.background_ex_one) // background drawable
.setAnimation(Fade.In.getAnimation(), Fade.Out.getAnimation()) // show and hide animations
.setDuration(4000) // you can use for auto close.
.alignBottom() // bottom align option.
.show();
- Close Minimal KSnack.
minimalKSnack.dismiss();
- Initialize KSnack.
KSnack kSnack = new KSnack(MainActivity.this);
- Set Features.
kSnack
.setListener(new KSnackBarEventListener() { // listener
@Override
public void showedSnackBar() {
System.out.println("Showed");
}
@Override
public void stoppedSnackBar() {
System.out.println("Stopped");
}
})
.setAction("Text", new View.OnClickListener() { // name and clicklistener
@Override
public void onClick(View v) {
System.out.println("Your action !");
}
})
.setMessage("Your message.") // message
.setTextColor(R.color.white) // message text color
.setBackColor(R.color.colorGray) // background color
.setButtonTextColor(R.color.white) // action button text color
.setBackgrounDrawable(R.drawable.background_ex_one) // background drawable
.setAnimation(Slide.Up.getAnimation(kSnack.getSnackView()), Slide.Down.getAnimation(kSnack.getSnackView()))
.setDuration(4000) // you can use for auto close.
.show();
- Close Minimal KSnack.
kSnack.dismiss();
kSnack.setAnimation(Fade.In.getAnimation(), Fade.Out.getAnimation()) // show and hide animations
minimalKSnack.setAnimation(Slide.Down.getAnimation(minimalKSnack.getSnackView()), Slide.Up.getAnimation(minimalKSnack.getSnackView()))
Slide animations need KSnack or MinimalKSnack view. You should use getSnackView()
or getMinimalSnackView()
functions for correct view object.
Step 1. Add the JitPack repository to your build file.
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency.
dependencies {
implementation 'com.github.onurkagan:KSnack:1.1.2'
}