标签: Splash 启动界面 Android SDK
[2].[代码] SplashScreen.java 跳至 [1] [2] [3]
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
public
class
SplashScreen
extends
Activity {
/**
* The thread to process splash screen events
*/
private
Thread mSplashThread;
/** Called when the activity is first created. */
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
// Splash screen view
setContentView(R.layout.splash);
final
SplashScreen sPlashScreen =
this
;
// The thread to wait for splash screen events
mSplashThread =
new
Thread(){
@Override
public
void
run(){
try
{
synchronized
(
this
){
// Wait given period of time or exit on touch
wait(
5000
);
}
}
catch
(InterruptedException ex){
}
finish();
// Run next activity
Intent intent =
new
Intent();
intent.setClass(sPlashScreen, MainActivity.
class
);
startActivity(intent);
stop();
}
};
mSplashThread.start();
}
/**
* Processes splash screen touch events
*/
@Override
public
boolean
onTouchEvent(MotionEvent evt)
{
if
(evt.getAction() == MotionEvent.ACTION_DOWN)
{
synchronized
(mSplashThread){
mSplashThread.notifyAll();
}
}
return
true
;
}
}
|
本文介绍了一个简单的Android启动屏幕(Splash Screen)实现方案。通过创建一个专门的Activity来展示启动画面,并利用线程等待机制,在设定的时间后自动跳转到主Activity。此外,还实现了触摸反馈功能,允许用户通过触摸操作提前结束启动过程。
1051

被折叠的 条评论
为什么被折叠?



