Android實(shí)現(xiàn)閃屏頁(yè)效果
本文實(shí)例為大家分享了Android實(shí)現(xiàn)閃屏頁(yè)效果的具體代碼,供大家參考,具體內(nèi)容如下
1.效果圖

2.閃屏頁(yè)邏輯及布局
2.1 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="跳過(guò)" android:textStyle="bold" android:textColor="#fff" android:background="#30000000" android:layout_gravity="right" android:layout_marginTop="30dp" android:layout_marginRight="30dp"/> </FrameLayout>
2.2 SplashActivity.java
通過(guò)Handler實(shí)現(xiàn)
public class SplashActivity extends AppCompatActivity {
//跳過(guò)按鈕
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);
}
//監(jiān)聽(tīng)事件
public void initEvent(){
btnSkip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//防止LoginActivity被打開(kāi)兩次
handler.removeCallbacks(runnableToLogin);
toLoginActivity();
}
});
}
/**
* 跳轉(zhuǎn)到登錄界面
*/
private void toLoginActivity(){
Intent intent = new Intent(this,LoginActivity.class);
startActivity(intent);
finish();
}
@Override
protected void onDestroy() {
super.onDestroy();
//防止內(nèi)存泄漏
handler.removeCallbacks(runnableToLogin);
}
}
3.設(shè)置主題樣式
3.1 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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android Handler實(shí)現(xiàn)閃屏頁(yè)倒計(jì)時(shí)代碼
- Android 自定義閃屏頁(yè)廣告倒計(jì)時(shí)view效果
- Android中使用Handler及Countdowntimer實(shí)現(xiàn)包含倒計(jì)時(shí)的閃屏頁(yè)面
- Android應(yīng)用閃屏頁(yè)延遲跳轉(zhuǎn)的三種寫法
- Android 實(shí)現(xiàn)閃屏頁(yè)和右上角的倒計(jì)時(shí)跳轉(zhuǎn)實(shí)例代碼
- Android?App實(shí)現(xiàn)閃屏頁(yè)廣告圖的全屏顯示實(shí)例
相關(guān)文章
Android 模擬器(JAVA)與C++ socket 通訊 分享
Android 模擬器(JAVA)與C++ socket 通訊 分享,需要的朋友可以參考一下2013-05-05
Android如何在App中啟動(dòng)系統(tǒng)鬧鐘
這篇文章主要為大家詳細(xì)介紹了Android如何在App中啟動(dòng)系統(tǒng)鬧鐘,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01
Android SurfaceView預(yù)覽變形完美解決方法
本篇文章主要介紹了Android SurfaceView預(yù)覽變形完美解決方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-04-04
解決Android Studio Log.v和Log.d不顯示的問(wèn)題
這篇文章主要介紹了解決Android Studio Log.v和Log.d不顯示的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-08-08
Eclipse NDK遷移到Android Studio的方法示例
本篇文章主要介紹了Eclipse NDK遷移到Android Studio的方法示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
Android Studio去除界面默認(rèn)標(biāo)題欄的方法
這篇文章主要介紹了Android Studio去除界面默認(rèn)標(biāo)題欄的方法,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2007-09-09
藍(lán)牙原理Android代碼實(shí)現(xiàn)
這篇文章主要為大家詳細(xì)介紹了藍(lán)牙原理Android代碼實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
Android基于CountDownTimer實(shí)現(xiàn)倒計(jì)時(shí)功能
這篇文章主要介紹了Android基于CountDownTimer實(shí)現(xiàn)倒計(jì)時(shí)功能,簡(jiǎn)單分析了基于CountDownTimer類實(shí)現(xiàn)倒計(jì)時(shí)功能的技巧,需要的朋友可以參考下2015-12-12

