在此简单记录一下,工作中用的的一些东西
1.思路很简单
xml布局,很简单就一张默认的全局图片
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mama.wemex3.ui.activity.SplashActivity">
<ImageView
android:id="@+id/iv_splash"
android:src="@mipmap/ic_launcher"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
2.build.gradle引入
compile 'com.github.bumptech.glide:glide:3.7.0'
3.SplashActivity 注意:里面用了最近比较火的Glide加载本地或者网络图片(crossFade是淡入淡出属性),加载之后通过thread开启线程设置3s后进入引导页面或者主页面
public class SplashActivity extends AppCompatActivity {
private ImageView iv_splash;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//全屏样式
iv_splash = (ImageView) findViewById(R.id.iv_splash);
//获取网络图片
Glide.with(this).load("http://pic41.nipic.com/20140507/18602184_142854861000_2.jpg").crossFade(3000).into(iv_splash);
//3s后关闭闪屏页面
new Thread(){
@Override
public void run() {
super.run();
try {
Thread.sleep(3000);
Intent intent = new Intent(SplashActivity.this,GuideActivity.class);
startActivity(intent);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
}
}
感觉是不是很简单,
小提示:
全屏显示也可以在AndroidManifest.xml 文件中配置
<activity android:name=".SplashActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Theme.AppCompat无全屏主题解决办法 (自己定义)
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light"> <item name="windowNoTitle">true</item> <item name="windowActionBar">false</item> <item name="android:windowFullscreen">true</item> <item name="android:windowContentOverlay">@null</item> </style>
<activity
android:name=".ui.activity.SplashActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
如果用到倒计时 可以用
CountDownTimer实现
虽然不好看,来张效果图