* MainActivity.java *
* *
************************************************************************/
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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;
}
}
/************************************************************************
* SplashActivity.java *
* 在src的資料夾裡建立此 .java 檔 *
************************************************************************/
public class SplashActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Thread(new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(3000);
startActivity(new Intent().setClass(SplashActivity.this, MainActivity.class));
/*如果要在三秒後跳到主頁面後返回不要跳回此頁,可加入這行*/
xsystarActivity.this.finish();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).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;
}
}
/************************************************************************
* activity_main.xml *
* *
************************************************************************/
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.test.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
/************************************************************************
* splash.xml *
* 自行在/res/layout資料夾下建立這個檔案 *
************************************************************************/
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="@drawable/darkgray" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/app_name"
android:src="@drawable/butterfly" />
</RelativeLayout>
/************************************************************************
* AndroidManifest.xml *
* *
************************************************************************/
<activity
//這邊要注意一下喔!! 你建立專案的名稱
android:name="com.example.test.MainActivity"
android:label="@string/app_name" >
</activity>
<activity android:name=".SplashActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
點入App的第一個畫面 |
3秒後跳轉至的頁面 |
沒有留言:
張貼留言