1

我想开始一项新活动,但只有在显示我的面包块之后。

我想使用 Crouton 的 onDisplayed() 函数 https://github.com/keyboardsurfer/Crouton/blob/master/library/src/de/keyboardsurfer/android/widget/crouton/LifecycleCallback.java

然后按如下方式调用我的活动

Intent i = new Intent(this, MyNewActivity.class);
startActivity(i);
finish();

我一直在尝试创建我的回调函数,但到目前为止没有运气......

谢谢!

4

1 回答 1

5

我解决如下。

在名为“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();
}
于 2013-10-07T13:57:01.377 回答