• Android Studio 引入Xui框架-简单应用


    Android Studio Flamingo | 2022.2.1 Patch 2 

    Android 11开发、Gradle Version 8.0、 jdk17

    源代码:GitHub - xuexiangjys/XUI: 💍A simple and elegant Android native UI framework, free your hands! (一个简洁而优雅的Android原生UI框架,解放你的双手!)

    参考手册:

    Home · xuexiangjys/XUI Wiki · GitHub

    快速继承Demo:

    GitHub - xuexiangjys/TemplateAppProject: Android template project, fast construction (integrated XUI, XUtil, XAOP, XPage, XUpdate, XHttp2, Umeng Statistics and Walle multi-channel package). Android空壳模板工程,快速搭建(集成了XUI、XUtil、XAOP、XPage、XUpdate、XHttp2、友盟统计和walle多渠道打包)

    1.在settings.gradle文件中加入依赖   maven { url "https://jitpack.io" }

    1. dependencyResolutionManagement {
    2. repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    3. repositories {
    4. google()
    5. mavenCentral()
    6. //导入maven
    7. maven { url "https://jitpack.io" }
    8. }
    9. }

    2.在build.gradle 引入   implementation 'com.github.xuexiangjys:XUI:1.1.5'

    1. dependencies {
    2. //xui
    3. implementation 'com.github.xuexiangjys:XUI:1.1.5'
    4. implementation 'androidx.appcompat:appcompat:1.4.1'
    5. implementation 'com.google.android.material:material:1.5.0'
    6. implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    7. testImplementation 'junit:junit:4.13.2'
    8. androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    9. androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    10. }

    3. 写个类继承 Application 重写onCreate方法 加入

             XUI.init(this); //初始化UI框架
            XUI.debug(true);  //开启UI框架调试日志

    1. import android.app.Application;
    2. import com.xuexiang.xui.XUI;
    3. public class XuiActivity extends Application {
    4. @Override
    5. public void onCreate() {
    6. super.onCreate();
    7. XUI.init(this); //初始化UI框架
    8. XUI.debug(true); //开启UI框架调试日志
    9. }
    10. }

    4.在AndroidManifest.xml中加入 这个类  android:name=".XuiActivity"

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android">
    3. <application
    4. <!-- 加入-->
    5. android:name=".XuiActivity"
    6. android:allowBackup="true"
    7. android:icon="@mipmap/ic_launcher"
    8. android:label="@string/app_name"
    9. android:roundIcon="@mipmap/ic_launcher_round"
    10. android:supportsRtl="true"
    11. android:theme="@style/Theme.MyAppday3">
    12. <activity
    13. android:name=".MainActivity"
    14. android:exported="true">
    15. <intent-filter>
    16. <action android:name="android.intent.action.MAIN" />
    17. <category android:name="android.intent.category.LAUNCHER" />
    18. </intent-filter>
    19. </activity>
    20. </application>
    21. </manifest>

    5.把样式改一下

    1. 基础主题类型:
    2. 大平板(10英寸, 240dpi, 1920*1200):XUITheme.Tablet.Big
    3. 小平板(7英寸, 320dpi, 1920*1200):XUITheme.Tablet.Small
    4. 手机(4.5英寸, 320dpi, 720*1280):XUITheme.Phone
    5. <resources xmlns:tools="http://schemas.android.com/tools">
    6. <!-- Base application theme. -->
    7. <style name="Base.Theme.MyAppday3" parent="XUITheme.Phone">
    8. <!-- Customize your light theme here. -->
    9. <!-- <item name="colorPrimary">@color/my_light_primary</item> -->
    10. </style>
    11. <style name="Theme.MyAppday3" parent="Base.Theme.MyAppday3" />
    12. </resources>

    6.即可在布局中添加相关组件

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. xmlns:app="http://schemas.android.com/apk/res-auto"
    4. xmlns:tools="http://schemas.android.com/tools"
    5. android:layout_width="match_parent"
    6. android:layout_height="match_parent"
    7. tools:context=".MainActivity">
    8. <ScrollView
    9. android:layout_width="match_parent"
    10. android:layout_height="wrap_content">
    11. <LinearLayout
    12. android:layout_width="match_parent"
    13. android:layout_height="wrap_content"
    14. android:orientation="vertical"
    15. android:gravity="center"
    16. >
    17. <com.xuexiang.xui.widget.button.roundbutton.RoundButton
    18. style="@style/RoundButton.Auto"
    19. android:layout_marginTop="20dp"
    20. android:text="默认圆角大小" />
    21. <com.xuexiang.xui.widget.button.roundbutton.RoundButton
    22. style="@style/RoundButton.Auto"
    23. android:layout_marginTop="20dp"
    24. android:text="自定义样式"
    25. android:textColor="@color/xui_default_round_btn_white_text"
    26. app:rb_backgroundColor="@color/xui_round_btn_green_bg"
    27. app:rb_borderColor="@color/xui_round_btn_green_bg" />
    28. <com.xuexiang.xui.widget.button.shadowbutton.ShadowButton
    29. android:layout_width="100dp"
    30. android:layout_height="100dp"
    31. android:layout_margin="16dp"
    32. app:sb_ripple_duration="2000"
    33. android:background="@mipmap/ic_launcher"
    34. app:sb_ripple_color="@color/app_color_theme_8"
    35. app:sb_color_pressed="@color/app_color_theme_6"
    36. app:sb_radius="6dp" />
    37. <com.xuexiang.xui.widget.button.ButtonView
    38. style="@style/ButtonView.Blue"
    39. android:layout_margin="20dp"/>
    40. <com.xuexiang.xui.widget.button.ButtonView
    41. style="@style/ButtonView.Green"
    42. android:layout_margin="20dp"/>
    43. <com.xuexiang.xui.widget.button.ButtonView
    44. style="@style/ButtonView.Gray"
    45. android:layout_margin="20dp"/>
    46. <!-- 倒计时button-->
    47. <com.xuexiang.xui.widget.button.CountDownButton
    48. android:id="@+id/bt_countdown4"
    49. style="@style/Button.Blue"
    50. android:text="获取验证码" />
    51. <com.xuexiang.xui.widget.button.switchbutton.SwitchButton
    52. android:id="@+id/sb_ios"
    53. style="@style/SwitchButtonStyle"
    54. android:layout_width="wrap_content"
    55. android:layout_height="wrap_content"
    56. app:swb_animationDuration="300"
    57. app:swb_backDrawable="@drawable/ios_back_drawable"
    58. app:swb_thumbDrawable="@drawable/ios_thumb_selector"
    59. app:swb_thumbMarginBottom="-8dp"
    60. app:swb_thumbMarginLeft="-5dp"
    61. app:swb_thumbMarginRight="-5dp"
    62. app:swb_thumbMarginTop="-2.5dp"
    63. app:swb_thumbRangeRatio="1.4" />
    64. <com.xuexiang.xui.widget.button.RippleView
    65. android:layout_width="match_parent"
    66. android:layout_height="wrap_content"
    67. android:layout_marginTop="?attr/xui_config_content_spacing_horizontal"
    68. app:rv_type="simpleRipple">
    69. <TextView
    70. android:layout_width="match_parent"
    71. android:layout_height="100dp"
    72. android:layout_gravity="center"
    73. android:layout_marginStart="?attr/xui_config_content_spacing_horizontal"
    74. android:layout_marginEnd="?attr/xui_config_content_spacing_horizontal"
    75. android:background="@color/app_color_theme_1"
    76. android:gravity="center"
    77. android:text="单波纹"
    78. android:textColor="@color/xui_config_color_white"
    79. android:textSize="20sp" />
    80. </com.xuexiang.xui.widget.button.RippleView>
    81. <!-- 悬浮按钮-->
    82. <com.google.android.material.floatingactionbutton.FloatingActionButton
    83. android:layout_width="50dp"
    84. android:layout_height="50dp"
    85. app:borderWidth="10px"
    86. android:backgroundTint="@color/app_color_theme_4"
    87. app:rippleColor="@color/app_color_theme_3"
    88. />
    89. <com.xuexiang.xui.widget.button.SwitchIconView
    90. android:id="@+id/switchIconView3"
    91. android:layout_width="wrap_content"
    92. android:layout_height="wrap_content"
    93. android:layout_gravity="center"
    94. android:padding="8dp"
    95. app:siv_disabled_alpha=".5"
    96. app:siv_disabled_color="#dadada"
    97. app:siv_enabled="true"
    98. app:siv_tint_color="#ffb700"
    99. app:srcCompat="@drawable/ic_camera" />
    100. <com.xuexiang.xui.widget.button.SmoothCheckBox
    101. android:id="@+id/scb"
    102. android:layout_width="40dp"
    103. android:layout_height="40dp"
    104. android:layout_margin="5dp"
    105. android:paddingTop="10dp"
    106. app:scb_color_checked="@color/app_color_theme_1" />
    107. <com.xuexiang.xui.widget.button.shinebutton.ShineButton
    108. android:id="@+id/shine_button"
    109. android:layout_width="30dp"
    110. android:layout_height="30dp"
    111. android:layout_gravity="center"
    112. app:sb_checked_color="#f26d7d"
    113. app:sb_icon_image="@drawable/ic_heart"
    114. app:sb_normal_color="@android:color/darker_gray" />
    115. <com.xuexiang.xui.widget.button.shinebutton.ShineButton
    116. android:id="@+id/shine_button_1"
    117. android:layout_width="30dp"
    118. android:layout_height="30dp"
    119. android:layout_gravity="center"
    120. android:src="@android:color/darker_gray"
    121. app:sb_allow_random_color="false"
    122. app:sb_big_shine_color="#FF6666"
    123. app:sb_checked_color="#FF6666"
    124. app:sb_click_animation_duration="200"
    125. app:sb_enable_flashing="false"
    126. app:sb_icon_image="@drawable/ic_like"
    127. app:sb_normal_color="@android:color/darker_gray"
    128. app:sb_shine_animation_duration="1500"
    129. app:sb_shine_count="15"
    130. app:sb_shine_distance_multiple="1.5"
    131. app:sb_shine_turn_angle="10"
    132. app:sb_small_shine_color="#CC9999"
    133. app:sb_small_shine_offset_angle="20" />
    134. <!-- button xui-->
    135. <com.xuexiang.xui.widget.button.ButtonView
    136. android:id="@+id/buttonView"
    137. style="@style/ButtonView.Green"
    138. android:layout_width="50dp"
    139. android:layout_height="50dp"
    140. android:layout_marginTop="237dp"
    141. android:layout_marginBottom="69dp"
    142. app:layout_constraintBottom_toTopOf="@+id/textView"
    143. app:layout_constraintEnd_toEndOf="parent"
    144. app:layout_constraintStart_toStartOf="parent"
    145. app:layout_constraintTop_toTopOf="parent" />
    146. <TextView
    147. android:layout_width="wrap_content"
    148. android:layout_height="wrap_content"
    149. android:text="Hello World!"
    150. app:layout_constraintBottom_toBottomOf="parent"
    151. app:layout_constraintEnd_toEndOf="parent"
    152. app:layout_constraintStart_toStartOf="parent"
    153. app:layout_constraintTop_toTopOf="parent" />
    154. </LinearLayout>
    155. </ScrollView>
    156. </LinearLayout>

    实例图: 

    相关资源:导入项目后,在源项目码中自己找 Ctrl+N 

  • 相关阅读:
    mysql存储过程
    全息干涉图补零尺寸与三种重构方法重建像间的关系研究
    Graph (discrete mathematics)
    测试十大法则
    ArrayList详解
    华为设备配置RSVP认证
    干货带图:前端深浅拷贝的实现
    如何在 Windows 10 中安装 WSL2 的 Linux 子系统
    关于POM声明为provided的依赖,运行程序时报错NoClassDefFoundError
    云计算面试题【后期】
  • 原文地址:https://blog.csdn.net/jiayou2020527/article/details/134513131