本篇文章为大家展示了Android开发中怎么实现一个闪屏页效果,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
闪屏页逻辑及布局
activity_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/splash"
android:scaleType="centerCrop"/>
<Button
android:id="@+id/splash_btn_skip"
android:layout_width="45dp"
android:layout_height="32dp"
android:text="跳过"
android:textStyle="bold"
android:textColor="#fff"
android:background="#30000000"
android:layout_gravity="right"
android:layout_marginTop="30dp"
android:layout_marginRight="30dp"/>
</FrameLayout>
SplashActivity.java
通过Handler实现
public class SplashActivity extends AppCompatActivity {
//跳过按钮
private Button btnSkip;
private Handler handler = new Handler();
private Runnable runnableToLogin = new Runnable() {
@Override
public void run() {
toLoginActivity();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
initView();
initEvent();
//延迟4秒
handler.postDelayed(runnableToLogin,4000);
}
//初始化组件
public void initView(){
btnSkip = findViewById(R.id.splash_btn_skip);
}
//监听事件
public void initEvent(){
btnSkip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//防止LoginActivity被打开两次
handler.removeCallbacks(runnableToLogin);
toLoginActivity();
}
});
}
/**
* 跳转到登录界面
*/
private void toLoginActivity(){
Intent intent = new Intent(this,LoginActivity.class);
startActivity(intent);
finish();
}
@Override
protected void onDestroy() {
super.onDestroy();
//防止内存泄漏
handler.removeCallbacks(runnableToLogin);
}
}
设置主题样式
style.xml中
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme_FullScreen" parent="AppTheme">
<item name="android:windowFullscreen">true</item>
</style>
</resources>
3.2 AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myrestaurant">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".LoginActivity"></activity>
<activity android:name=".SplashActivity"
android:theme="@style/AppTheme_FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
上述内容就是Android开发中怎么实现一个闪屏页效果,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。