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

2.閃屏頁邏輯及布局
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="跳過" 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
通過Handler實(shí)現(xiàn)
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);
}
//監(jiān)聽事件
public void initEvent(){
btnSkip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//防止LoginActivity被打開兩次
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í)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android開發(fā)入門之Notification用法分析
這篇文章主要介紹了Android中Notification用法,較為詳細(xì)的分析了Notification的功能、使用步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-07-07
一文詳解?Compose?Navigation?的實(shí)現(xiàn)原理
這篇文章主要介紹了一文詳解?Compose?Navigation的實(shí)現(xiàn)原理,文章通告圍繞主題展開詳細(xì)的相關(guān)內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-08-08
Android中使用TagFlowLayout制作動(dòng)態(tài)添加刪除標(biāo)簽
這篇文章主要介紹了Android中使用TagFlowLayout制作動(dòng)態(tài)添加刪除標(biāo)簽的步驟詳解,需要的朋友參考下吧2017-07-07
Android應(yīng)用中拍照后獲取照片路徑并上傳的實(shí)例分享
這篇文章主要介紹了Android應(yīng)用中拍照后獲取照片路徑并上傳的實(shí)例分享,文中使用MultipartEntityBuilder制作了一個(gè)簡(jiǎn)單的上傳工具,需要的朋友可以參考下2016-03-03
Android?Java?try?catch?失效問題及解決
這篇文章主要介紹了Android?Java?try?catch?失效問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11
Android checkbox的listView(多選,全選,反選)具體實(shí)現(xiàn)方法
由于listview的一些特性,剛開始寫這種需求的功能的時(shí)候都會(huì)碰到一些問題,重點(diǎn)就是存儲(chǔ)每個(gè)checkbox的狀態(tài)值,在這里分享出了完美解決方法:2013-06-06
Android入門之利用Spinner實(shí)現(xiàn)彈出選擇對(duì)話框
這篇文章主要為大家詳細(xì)介紹了Android里如何巧用Spinner做彈出選擇對(duì)話框,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以了解一下2022-11-11
Android軟件啟動(dòng)動(dòng)畫及動(dòng)畫結(jié)束后跳轉(zhuǎn)的實(shí)現(xiàn)方法
這篇文章主要介紹了Android軟件啟動(dòng)動(dòng)畫及動(dòng)畫結(jié)束后跳轉(zhuǎn)的實(shí)現(xiàn)方法,實(shí)例分析了Android圖片播放及定時(shí)器的相關(guān)使用技巧,非常具有使用價(jià)值,需要的朋友可以參考下2015-10-10
Android中ViewPager帶來的滑動(dòng)卡頓問題解決要點(diǎn)解析
這里我們主要針對(duì)ViewGroup的SwipeRefreshLayout中引入ViewPager所引起的滑動(dòng)沖突問題進(jìn)行討論,一起來看一下Android中ViewPager帶來的滑動(dòng)卡頓問題解決要點(diǎn)解析:2016-06-06

