Parcourir la source

app渐进式启动页面初始化

everywindchase il y a 9 mois
Parent
commit
f7219fe8e4

+ 6 - 4
app/src/main/AndroidManifest.xml

@@ -17,15 +17,14 @@
                 android:name=".activity.LaunchActivity"
                 android:exported="true"
                 android:configChanges="screenSize|keyboardHidden|orientation|keyboard"
-                android:windowSoftInputMode="adjustPan|stateHidden">
+                android:windowSoftInputMode="adjustPan|stateHidden"
+                android:theme="@style/XUITheme.Launch.Demo"
+        >
 
             <intent-filter>
                 <action android:name="android.intent.action.MAIN"/>
                 <category android:name="android.intent.category.LAUNCHER"/>
             </intent-filter>
-<!--            <meta-data-->
-<!--                    android:name="android.app.shortcuts"-->
-<!--                    android:resource="@xml/shortcuts" />-->
 
         </activity>
 
@@ -33,6 +32,9 @@
 
         <activity
                 android:name=".activity.MainActivity"
+                android:configChanges="screenSize|keyboardHidden|orientation|keyboard|locale|layoutDirection"
+                android:launchMode="singleTask"
+                android:windowSoftInputMode="adjustPan|stateHidden"
         >
 
 

+ 24 - 1
app/src/main/java/jx/cn/escort/activity/LaunchActivity.kt

@@ -1,6 +1,29 @@
 package jx.cn.escort.activity
 
-class LaunchActivity {
+
+
+import com.xuexiang.xui.widget.activity.BaseSplashActivity
+import jx.cn.escort.R
+import jx.cn.escort.utils.ActivityUtils
+
+
+
+class LaunchActivity: BaseSplashActivity()  {
+
+
+    override fun getSplashDurationMillis(): Long {
+        return 500
+    }
+
+    override fun onCreateActivity() {
+        initSplashView(R.drawable.xui_config_bg_splash);
+        startSplash(true);
+    }
+
+    override fun onSplashFinished() {
+        ActivityUtils.startActivity(this,MainActivity::class.java)
+        finish()
+    }
 
 
 }

+ 27 - 0
app/src/main/java/jx/cn/escort/utils/ActivityUtils.kt

@@ -0,0 +1,27 @@
+package jx.cn.escort.utils
+
+
+import android.content.Context
+import android.content.Intent
+
+ class ActivityUtils {
+
+
+     companion object{
+         /**
+          * <p>启动活动层,使用了内联函数和reified,
+          *  inline是为了编译直接替换,reified关键字修饰的泛型直接在编译时候确定类型而不是运行时候进行擦除,
+          *  这样做是为了提高运行性能
+          * </p>
+          */
+         @JvmStatic
+         inline  fun <reified  T> startActivity(context: Context, cls: Class<T>) {
+             val intent=Intent(context,T::class.java)
+             context.startActivity(intent)
+         }
+
+
+     }
+
+
+}

BIN
app/src/main/res/drawable-hdpi/ic_splash_app_logo_xui.png


BIN
app/src/main/res/drawable-hdpi/ic_splash_company_logo_xuexiang.png


BIN
app/src/main/res/drawable-hdpi/icon_back_black.png


+ 18 - 0
app/src/main/res/drawable/xui_config_bg_splash.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--有公司logo-->
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
+    android:opacity="opaque">
+    <item android:drawable="@color/xui_config_color_white"/>
+
+    <item android:bottom="@dimen/xui_config_app_logo_bottom">
+        <bitmap
+            android:gravity="center"
+            android:src="@drawable/ic_splash_app_logo_xui"/>
+    </item>
+
+    <item android:bottom="@dimen/xui_config_company_logo_bottom">
+        <bitmap
+            android:gravity="bottom"
+            android:src="@drawable/ic_splash_company_logo_xuexiang"/>
+    </item>
+</layer-list>

+ 18 - 0
app/src/main/res/layout/activity_launch.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:tools="http://schemas.android.com/tools"
+        xmlns:app="http://schemas.android.com/apk/res-auto"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        tools:context=".activity.LaunchActivity">
+    <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="Hello World!"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintTop_toTopOf="parent"/>
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 5 - 0
app/src/main/res/layout/activity_main.xml

@@ -6,6 +6,11 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         tools:context=".activity.MainActivity">
+
+
+    <include
+        layout="@layout/layout_top_bar"
+    />
     <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"

+ 36 - 0
app/src/main/res/layout/layout_top_bar.xml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:tools="http://schemas.android.com/tools"
+        xmlns:app="http://schemas.android.com/apk/res-auto"
+        android:layout_width="match_parent"
+        android:layout_height="62dp"
+        android:background="@color/xui_config_color_white"
+>
+
+
+
+
+    <com.xuexiang.xui.widget.actionbar.TitleBar
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="5dp"
+            android:background="#83cbc5"
+            app:tb_barHeight="65dp"
+            app:tb_dividerColor="@color/xui_config_color_red"
+            app:tb_leftText="回退"
+            app:tb_sideTextPadding="20dp"
+            app:tb_actionPadding="20dp"
+            app:tb_titleText="这是一个Title" tools:ignore="MissingConstraints"
+            app:tb_actionTextColor="@color/xui_config_color_red"
+            app:tb_useThemeColor="false"
+            app:tb_centerGravity="left"
+            app:tb_leftImageResource="@drawable/icon_back_black"
+    />
+
+
+
+
+
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 8 - 0
app/src/main/res/values/stlyes.xml

@@ -0,0 +1,8 @@
+<resources>
+    <!--窗体背景,这个背景能在第一时间显示, 避免启动时白屏,黑屏问题-->
+    <style name="XUITheme.Launch.Demo">
+        <item name="android:windowBackground">@drawable/xui_config_bg_splash</item>
+        <item name="xui_config_splash_app_logo">@drawable/ic_splash_app_logo_xui</item>
+        <item name="xui_config_splash_company_logo">@drawable/ic_splash_company_logo_xuexiang</item>
+    </style>
+</resources>

+ 0 - 28
app/src/main/res/xml/shortcuts.xml

@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<shortcuts xmlns:android="http://schemas.android.com/apk/res/android"
-           xmlns:tools="http://schemas.android.com/tools">
-
-    <shortcut
-            android:icon="@drawable/ic_action_setting"
-            android:shortcutId="shortcut_setting"
-            android:shortcutShortLabel="@string/shortcut_label_setting"
-            tools:targetApi="n_mr1">
-
-        <intent
-                android:action="android.intent.action.VIEW"
-                android:targetClass="com.xuexiang.xuidemo.activity.SettingsActivity"
-                android:targetPackage="com.xuexiang.xuidemo" />
-    </shortcut>
-
-    <shortcut
-            android:icon="@drawable/ic_action_search"
-            android:shortcutId="shortcut_search"
-            android:shortcutShortLabel="@string/shortcut_label_search"
-            tools:targetApi="n_mr1">
-        <intent
-                android:action="android.intent.action.VIEW"
-                android:targetClass="com.xuexiang.xuidemo.activity.SearchComponentActivity"
-                android:targetPackage="com.xuexiang.xuidemo" />
-    </shortcut>
-
-</shortcuts>