在我的應用程序中,我創建了一個閃屏類型的東西在android中。它應該保持5秒鐘。我的問題是如何在5秒後自動顯示其他活動?啓動畫面沒有按鈕,相反它應該在5秒後自動顯示另一個活動,而不需要點擊按鈕。並且請指導我如何設計新的全屏活動。我從堆棧溢出得到了這段代碼,但由於我是初學者,我不知道在哪裏添加這段代碼,任何人都可以告訴我。全屏活動設計和自動啓動新活動
-4
A
回答
0
你可以找到關於本教程如何創建啓動畫面:https://www.youtube.com/watch?v=XwOuTjUFexE
0
開機畫面加載添加下面的代碼之後在上創建
try {
Thread.sleep(5000);// You can change this depending on the requirement
Intent intent = new Intent(SplashActivity.this,SecondActivity.class);
startActivity(intent);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
你的第二個活動將在5秒鐘後自動被加載。
爲了使活動全屏的setContentView前添加以下線:
getWindow()setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.your_activity_layout);
}
1
因此可以說你已經爲你的閃屏創建了一個佈局。 然後你需要爲你的啓動畫面創建一個活動。
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash); //The layout for this activity
Thread timerThread = new Thread(){
public void run(){
try {
sleep(5000); //After 5 seconds your next activity will be displayed
} catch(InterruptedException e){
e.printStackTrace();
} finally {
Intent intent = new Intent(getBaseContext, MainActivity.class); // The next activity you want to start
startActivity(intent);
}
}
};
timerThread.start();
}
@Override
protected void onPause() {
super.onPause();
finish();
}}
然後remeber編輯您的活動類別在AndroidManifest.xml文件的啓動畫面類別應該是.LAUNCHER,而你的主要活動應.DEFAULT
<activity
android:name=".SplashScreen"
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=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
0
使用閃屏驗證碼活動更改時間如你所願......
public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo/company
*/
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, Login_Activity.class);
startActivity(i);
//overridePendingTransition(R.anim.fadein,R.anim.fadeout);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
相關問題
- 1. 全屏啓動wifi設置活動
- 2. 非全屏滾動活動
- 3. 啓動活動時自動刷新
- 4. 非全屏活動
- 5. 如何在重新啓動後立即啓動鎖屏活動?
- 6. Android活動重新啓動
- 7. Android - 無法在設備啓動時自動啓動活動?
- 8. 啓動活動
- 9. 設計滑動活動android
- 10. 活動的onStop()在啓動另一個全屏時未被調用活動
- 11. 當移動到活動時自動啓動倒計時
- 12. Android活動自動啓動 - 不需要
- 13. 真正的全屏活動
- 14. 如何做全屏活動?
- 15. Android活動設計
- 16. 啓動InCallScreen活動
- 17. Box2d:設置活動和不活動
- 18. 啓動活動超時,因爲活動啓動另一個活動
- 19. 如何從其他活動啓動啓動器活動?
- 20. 將當前活動設置爲啓動活動
- 21. 在不重新啓動活動的情況下恢復活動
- 22. 啓動新活動時發生綁定事務失敗活動
- 23. 安卓4.2:主要活動actionbar隱藏啓動新的活動
- 24. 關閉父活動並啓動一個新活動
- 25. 使用活動組時,無法從alertdialog onclicklistener啓動新活動
- 26. 半屏活動
- 27. 活動和子活動
- 28. WPF活動和活動
- 29. 啓動器啓動的活動,自定義動畫
- 30. 活動啓動時自動啓動執行
不如海在谷歌''如何處理Splash屏幕在Android?' –
可能重複的[如何設置我的啓動畫面的時間限制?](http://stackoverflow.com/questions/19491073/how-do-i -set-A-時限到我,閃屏) –