Android动态加载启动页

来源:互联网 发布:手机数据流量无法上网 编辑:程序博客网 时间:2024/06/08 10:33
public class MainActivity extends Activity {private Dialog splashDialog;@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    //1.创建     Display display = this.getWindowManager().getDefaultDisplay();     Dialog dialog = new Dialog(this);     LinearLayout root = new LinearLayout(this);     root.setMinimumHeight(display.getHeight());     root.setMinimumWidth(display.getWidth());     root.setOrientation(LinearLayout.VERTICAL);     root.setBackgroundColor(Color.BLACK);     root.setLayoutParams(new     LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,     方式一:     root.setBackgroundResource(R.drawable.ic_launcher);     方式二:     ImageView img = new ImageView(context);        img.setImageBitmap(bitmap);        root.addView(img);     // Create and show the dialog     splashDialog = new Dialog(this,     android.R.style.Theme_Translucent_NoTitleBar);     // check to see if the splash screen should be full screen     if ((this.getWindow().getAttributes().flags &     WindowManager.LayoutParams.FLAG_FULLSCREEN)     == WindowManager.LayoutParams.FLAG_FULLSCREEN) {     splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,     WindowManager.LayoutParams.FLAG_FULLSCREEN);     }     splashDialog.setContentView(root);     splashDialog.setCancelable(false);     //计时3秒后显示     CountDownTimer timer = new CountDownTimer(2 * 1000, 1000) {     @Override     public void onTick(long millisUntilFinished) {     }     @Override     public void onFinish() {     splashDialog.show();     }     };     timer.start();}}

2.关闭销毁

    if (splashDialog != null && splashDialog.isShowing()) {        splashDialog.dismiss();        splashDialog = null;    }
0 0
原创粉丝点击