我想在登录屏幕出现之前运行设计页面...因此,如何将设计页面保持几秒钟?

最佳答案

您可以使用启动屏幕的概念来执行此操作。
请参见以下代码:

public class SplashScreen extends Activity {
    protected boolean _active = true;
    protected int _splashTime = 2000; // time to display the splash screen in ms
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        Thread splashTread = new Thread() {
                @Override
                public void run() {
                    try {
                        int waited = 0;
                        while(_active && (waited < _splashTime)) {
                            sleep(100);
                            if(_active) {
                                waited += 100;
                            }
                        }
                    } catch(InterruptedException e) {
                        // do nothing
                    } finally {
                        finish();

                        startActivity(new Intent("com.live.A"));
                        stop();
                    }
                }
            };
            splashTread.start();
    }

}


其中A是您要在启动屏幕之后显示的屏幕,而com.live是您的软件包名称

希望对你有帮助 :)

10-08 09:20