您的位置:首页 > 移动开发 > Android开发

为Android应用程序添加欢迎界面

2015-01-20 14:49 260 查看
欢迎界面代码如下:

[java] view
plaincopy

package com.example.weichat.UI;

import android.os.Bundle;

import android.os.Handler;

import android.app.Activity;

import android.content.Intent;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.Toast;

public class WelcomeA extends Activity

{

@Override

protected void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

new Handler().postDelayed(new Runnable()

{

@Override

public void run()

{

// TODO Auto-generated method stub

Intent intent=new Intent(WelcomeA.this,WhatsnewPagesA.class);

startActivity(intent);

WelcomeA.this.finish();

}

}, 2000);

}

}

欢迎界面的Layout设置如下:

[html] view
plaincopy

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".WelcomeA" >

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:text="@string/hello_world" />

</RelativeLayout>

主界面的程序代码如下:

[java] view
plaincopy

package com.example.weichat.UI;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.Toast;

public class WhatsnewPagesA extends Activity

{

@Override

protected void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.start);

}

@Override

public boolean onCreateOptionsMenu(Menu menu)

{

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}

@Override

public boolean onOptionsItemSelected(MenuItem item)

{

//实现点击后查看相关的效果

if (item.getItemId()==R.id.menu_settings)

{

Intent intent = new Intent(this, WhatsnewPagesA.class);

startActivity(intent);

} else

{

Toast.makeText(this, "该软件由CDersTeam开发,版权归CDersTeam所有,任何侵权行为将负法律责任", Toast.LENGTH_LONG).show();

}

return true;

}

}

主界面的页面设置如下:

[html] view
plaincopy

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Welcome" />

</LinearLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: