我解决如下。
在名为“TestActivity”的活动中,我调用了:
showCroutonMsgThenGoToActivity(text);
在同一个类中,我添加了这些功能:
public void showCroutonMsgThenGoToActivity(String text) {
Crouton toShow = null;
LifecycleCallback myCallback = new LifecycleCallback() {
public void onDisplayed() {
// do nothing
}
// Will be called when your {@link Crouton} has been removed.
public void onRemoved() {
skipToNextActivity(MyNewActivity.class);
}
};
//create config
Configuration myConfig = new Configuration.Builder().
setDuration(1000)
.build();
//create style
Style myStyle = new Style.Builder().setConfiguration(myConfig)
.setBackgroundColor(R.color.green) //check your color!
.build();
//apply my custom stile
toShow = Crouton.makeText(TestActivity.this, text, myStyle);
toShow.setLifecycleCallback(myCallback);
toShow.show();
}
private void skipToNextActivity(Class c) {
// go to next activity
Intent i = new Intent(this, c);
startActivity(i);
finish();
}