作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想开始一项新 Activity ,但只能在展示我的面包丁之后。
我想使用 Crouton 的 onDisplayed() 函数 https://github.com/keyboardsurfer/Crouton/blob/master/library/src/de/keyboardsurfer/android/widget/crouton/LifecycleCallback.java
然后如下调用我的 Activity
Intent i = new Intent(this, MyNewActivity.class);
startActivity(i);
finish();
我一直在尝试创建我的回调函数,但到目前为止还没有成功...
谢谢!
最佳答案
我的解决方法如下。
在名为“TestActivity”的 Activity 中,我调用了:
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();
}
关于java - Android:如何在 Crouton onDisplayed() 上使用回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19177966/
我是一名优秀的程序员,十分优秀!