gpt4 book ai didi

java - Android:如何在 Crouton onDisplayed() 上使用回调

转载 作者:行者123 更新时间:2023-11-29 07:54:02 26 4
gpt4 key购买 nike

我想开始一项新 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com