zoukankan      html  css  js  c++  java
  • android打造一个简单的欢迎界面

    现在的好多安卓软件开始的时候都有一个欢迎界面,下面就跟随我一起来做一个简单的欢迎界面。

    先将MainActivity的代码贴出:

    package com.example.article4_welcome;
    
    import java.util.Timer;
    import java.util.TimerTask;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    
    public class MainActivity extends Activity {
    
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Timer time = new Timer();
            final Intent intent = new Intent(this, Login.class);
            TimerTask task = new TimerTask() {
    
                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    startActivity(intent);
                    MainActivity.this.finish();// 将本个activity结束,此句可有可无,看实际情况。
                }
            };
            time.schedule(task, 2000);// 2秒进行跳转
        }
    
    }

    其中Login.java是自己新建的一个类,贴出Login.java的代码:

    package com.example.article4_welcome;
    
    import android.annotation.SuppressLint;
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.Toast;
    
    @SuppressLint("ShowToast")
    public class Login extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            Toast.makeText(this, "欢迎进入登录界面", 1000).show();
        }
    
    }

    内容很简单呢,可以根据自己的方式拓展。

    下面是xml文件,本文只利用了一个main.xml(main_activity.xml)文件,加载一张图片。

    贴出代码:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/firstpic"
        tools:context=".MainActivity" >
    
    </LinearLayout>

    现在基本算是完工,但是最重要的一环节是修改配置文件。来看配置文件:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.article4_welcome"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.article4_welcome.MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name=".Login" >
            </activity>
        </application>
    
    </manifest>

    只是多了一行代码,

    <activity android:name=".Login" >
            </activity>
    利用这个进行跳转
    完工,可以运行了。感谢观看。
  • 相关阅读:
    hadoop balance
    随笔
    ubuntu server 使用parted分区
    程序员内功续
    hadoop——hdfs多硬盘挂载
    hdfs老数据压缩备份的一些问题20120521
    hadoop balance failed
    hoj 2524 Allocate Dormitories 二分图的最大匹配
    HDOJ 分类(转)
    hoj 3008 Matryoshka Dolls Again 最大独立子集
  • 原文地址:https://www.cnblogs.com/linzhichao86/p/linzhichao.html
Copyright © 2011-2022 走看看