android开发之欢迎界面的小例子

2016-02-19 09:26 41 1 收藏

今天图老师小编给大家精心推荐个android开发之欢迎界面的小例子教程,一起来看看过程究竟如何进行吧!喜欢还请点个赞哦~

【 tulaoshi.com - 编程语言 】

首先你得写好xml文件,这也是最主要的。

然后,在activity中加入一个线程,延时2秒,用来跳转到主界面。

activity中线程代码如下:(顺便检测一下网络是否打开)

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

[java]

代码如下:

@Override
    protected void onStart() {
        super.onStart();
        if(SPAN style="COLOR: #ff0000"isNetworkConnected()/SPAN){
            new Thread(){
                @Override
                public void run() {
                    try {
                        Thread.sleep(2000);
                        Intent intent = new Intent(SPAN style="COLOR: #ff0000"SplashActivity.this/SPAN,SPAN style="COLOR: #ff0000"CompusAssistMain.class/SPAN);
                        startActivity(intent);
                        finish();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            }.start();
        }else{
            //弹出对话框 让用户设置网络 
            AlertDialog.Builder builder = new Builder(this);
            builder.setTitle("设置网络");
            builder.setMessage("网络错误请设置网络");
            builder.setPositiveButton("设置网络", new OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent();
                    intent.setClassName(SPAN style="COLOR: #ff6666""com.android.settings"/SPAN, SPAN style="COLOR: #ff6666""com.android.settings.WirelessSettings"/SPAN);
                    startActivity(intent);
                }
            });
            builder.setNegativeButton("取消", new OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            });
            builder.create().show();
        }
    }

@Override
 protected void onStart() {
  super.onStart();
  if(isNetworkConnected()){
   new Thread(){
    @Override
    public void run() {
     try {
      Thread.sleep(2000);
      Intent intent = new Intent(SplashActivity.this,CompusAssistMain.class);
      startActivity(intent);
      finish();
     } catch (InterruptedException e) {
      e.printStackTrace();
     }

    }
   }.start();
  }else{
   //弹出对话框 让用户设置网络
   AlertDialog.Builder builder = new Builder(this);
   builder.setTitle("设置网络");
   builder.setMessage("网络错误请设置网络");
   builder.setPositiveButton("设置网络", new OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
     Intent intent = new Intent();
     intent.setClassName("com.android.settings", "com.android.settings.WirelessSettings");
     startActivity(intent);
    }
   });
   builder.setNegativeButton("取消", new OnClickListener() {

    public void onClick(DialogInterface dialog, int which) {
     finish();
    }
   });
   builder.create().show();
  }
 }检测网络的类isNetWorkConnected():


[java]
代码如下:

SPAN style="WHITE-SPACE: pre" /SPAN/**
     * 判断系统的网络是否可用
     * @return
     */
    private boolean isNetworkConnected(){
        ConnectivityManager cm =    (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
        NetworkInfo info =cm.getActiveNetworkInfo();
        if(info!=null&&info.isConnected()){
            return true;
        }else {
            return false ;
        }
    

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

 /**
  * 判断系统的网络是否可用
  * @return
  */
 private boolean isNetworkConnected(){
  ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
  NetworkInfo info =cm.getActiveNetworkInfo();
  if(info!=null&&info.isConnected()){
   return true;
  }else {
   return false ;
  }


这样就完成了一个欢迎界面,给自已的应用加点色彩。当然还要添加配置在Manifest文件中
[html]
代码如下:

activity
            android:name="com.yan.compusassist.SplashActivity"
            android:label="@string/application_name"
            intent-filter
                action android:name="android.intent.action.MAIN" /
                category android:name="android.intent.category.LAUNCHER" /
            /intent-filter
        /activity

activity
            android:name="com.yan.compusassist.SplashActivity"
            android:label="@string/application_name"
            intent-filter
                action android:name="android.intent.action.MAIN" /
                category android:name="android.intent.category.LAUNCHER" /
            /intent-filter
        /activity


这样它就会打开应用,启动第一个activity 界面。

来源:http://www.tulaoshi.com/n/20160219/1590786.html

延伸阅读
代码如下: package com.aslibra.test; import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.util.Log; import android.view.Window; import android.widget.ImageView; public class test extends Activity {   ImageView iv;   @Override   public void onC...
标签: Web开发
html head meta http-equiv="Content" content="text/html;chartset=utf-8" titletest drag/title style type="text/css" !-- .drag { width:100px; height:100px; position:absolute; left:10px; top:10px; background-color:blue; } -- /style script type="text/javascript" !-- function drag(target,event) {    var deltaX = e...
    要获取正在运行的任务,首先需要声明一个活动对象管理器(ActivityManager) 所有的活动任务都属于此,然后通过获取服务可以得到所有的活动对象,然后通过活动对象可以得到所有运行的任务和服务,当然要获取服务和任务是使用不同的方法,但是方式是一样的。下面是获取代码: 代码 代码如下: void getTask() {   ...
QQ界面的模拟实现(上) 作者:小帅 下载源代码 大凡用过电脑,上过网的朋友都用过QQ,对QQ的一些交互界面可能垂慕已久,的确,无论是其生动的企鹅形象,还是“滴滴的”消息声音,以及“刷”的菜单等功能,简单单的消息发送,以及快速的回显和众多卡通的QQ头像等铸就了其在网络的良好地位,本人对其研究虽不够...
首先下载 android SDK 最新版。不过最新版的 SDK 已经明确声明“The Android SDK archive now only contains the tools. It no longer comes populated with a specific Android platform or Google add-on. Instead you use the SDK Manager to install or update SDK components such as platforms,tools, add-ons, and documentation.”,所...

经验教程

218

收藏

54
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部

如果您有什么好的建议或者疑问,可以联系我们。 商务合作QQ:3272218541;3282258740。商务合作微信:13319608704;13319603564。

加好友请备注机构名称。让我们一起学习、一起进步tulaoshi.com 版权所有 © 2019 All Rights Reserved. 湘ICP备19009391号-3

微信公众号