android in practice_Displaying splash screens with timers(MyMovies project)
16lz
2021-01-26
You want to execute a delayed task that executes its logic only after a certain amountof time has passed.
The splash image can be dropped in the res/drawables folder:splash.png
The layout for a splash screen Activity:splash_screen.xml:
<?xml version="1.0" encoding="utf-8"?><merge xmlns:android="http://schemas.android.com/apk/res/android"> <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitXY" android:src="@drawable/splash" /></merge>We also need to define the new Activity in the manifestfile. Because it’ll be the first Activity that’s launched, it’ll take the place of theMyMovies Activity.
......... <activity android:name=".SplashScreen" android:label="@string/title_myMovie" android:theme="@style/SplashScreen"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MyMovies" />.........
We want the splash screen to befullscreen, so add the following code to your styles.xml:
<style name="SplashScreen" parent="@android:style/Theme.Black"><item name="android:windowNoTitle">true</item></style>
create the activity class SplashScreen
public class SplashScreen extends Activity { public static final int SPLASH_TIMEOUT = 2000; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash_screen); new Timer().schedule(new TimerTask(){@Overridepublic void run() {// TODO Auto-generated method stubproceed();} }, SPLASH_TIMEOUT); } public boolean onTouchEvent(MotionEvent event){ if(event.getAction()==MotionEvent.ACTION_DOWN){ proceed(); } return super.onTouchEvent(event); } private void proceed() { if(this.isFinishing()){ return; } startActivity(new Intent(SplashScreen.this,MyMovies.class)); finish(); }}
The task itself creates an Intent to launch our landingscreen (the MyMovies main Activity).
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer