久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

Android實現閃屏頁效果

瀏覽:2日期:2022-09-21 15:20:15

本文實例為大家分享了Android實現閃屏頁效果的具體代碼,供大家參考,具體內容如下

1.效果圖

Android實現閃屏頁效果

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='http://m.baoyu77737.com/bcjs/@drawable/splash' android:scaleType='centerCrop'/> <Button android: 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實現

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); }}

3.設置主題樣式

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>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: 五大连池市| 涪陵区| 贡嘎县| 玛多县| 望奎县| 华亭县| 云林县| 阜宁县| 平武县| 桃江县| 宜丰县| 新建县| 杭锦后旗| 沽源县| 永川市| 峨边| 泰和县| 屏山县| 喀什市| 富裕县| 博白县| 车致| 武宁县| 岗巴县| 崇文区| 肇东市| 连江县| 龙岩市| 古丈县| 清新县| 洛隆县| 台东市| 祁阳县| 盐亭县| 庆安县| 余庆县| 阳山县| 健康| 海南省| 焉耆| 岐山县|