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='http://www.piao2010.com/bcjs/@drawable/splash' android:scaleType='centerCrop'/> <Button android: 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í)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. php使用正則驗(yàn)證密碼字段的復(fù)雜強(qiáng)度原理詳細(xì)講解 原創(chuàng)2. 基于javaweb+jsp實(shí)現(xiàn)企業(yè)車(chē)輛管理系統(tǒng)3. HTML5實(shí)戰(zhàn)與剖析之觸摸事件(touchstart、touchmove和touchend)4. ASP將數(shù)字轉(zhuǎn)中文數(shù)字(大寫(xiě)金額)的函數(shù)5. Jsp servlet驗(yàn)證碼工具類(lèi)分享6. jscript與vbscript 操作XML元素屬性的代碼7. 基于PHP做個(gè)圖片防盜鏈8. Jsp+Servlet實(shí)現(xiàn)文件上傳下載 文件列表展示(二)9. asp.net core 認(rèn)證和授權(quán)實(shí)例詳解10. XML在語(yǔ)音合成中的應(yīng)用
