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

news/2024/7/16 8:05:18 标签: android studio, android, ide

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" }

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        //导入maven
        maven { url "https://jitpack.io" }
    }
}

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

dependencies {

    //xui
    implementation 'com.github.xuexiangjys:XUI:1.1.5'

    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

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

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

import android.app.Application;

import com.xuexiang.xui.XUI;

public class XuiActivity extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

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

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

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <application
          <!-- 加入-->
        android:name=".XuiActivity"

        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/Theme.MyAppday3">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

5.把样式改一下

基础主题类型:

大平板(10英寸, 240dpi, 1920*1200):XUITheme.Tablet.Big


小平板(7英寸, 320dpi, 1920*1200):XUITheme.Tablet.Small


手机(4.5英寸, 320dpi, 720*1280):XUITheme.Phone


<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Base.Theme.MyAppday3" parent="XUITheme.Phone">
        <!-- Customize your light theme here. -->
        <!-- <item name="colorPrimary">@color/my_light_primary</item> -->
    </style>

    <style name="Theme.MyAppday3" parent="Base.Theme.MyAppday3" />
</resources>

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

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context=".MainActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center"
        >
    <com.xuexiang.xui.widget.button.roundbutton.RoundButton
        style="@style/RoundButton.Auto"
        android:layout_marginTop="20dp"
        android:text="默认圆角大小" />

    <com.xuexiang.xui.widget.button.roundbutton.RoundButton
        style="@style/RoundButton.Auto"
        android:layout_marginTop="20dp"
        android:text="自定义样式"
        android:textColor="@color/xui_default_round_btn_white_text"
        app:rb_backgroundColor="@color/xui_round_btn_green_bg"
        app:rb_borderColor="@color/xui_round_btn_green_bg" />

    <com.xuexiang.xui.widget.button.shadowbutton.ShadowButton
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_margin="16dp"
        app:sb_ripple_duration="2000"
        android:background="@mipmap/ic_launcher"
        app:sb_ripple_color="@color/app_color_theme_8"
        app:sb_color_pressed="@color/app_color_theme_6"
        app:sb_radius="6dp" />



    <com.xuexiang.xui.widget.button.ButtonView
        style="@style/ButtonView.Blue"
        android:layout_margin="20dp"/>

    <com.xuexiang.xui.widget.button.ButtonView
        style="@style/ButtonView.Green"
        android:layout_margin="20dp"/>

    <com.xuexiang.xui.widget.button.ButtonView
        style="@style/ButtonView.Gray"
        android:layout_margin="20dp"/>
<!-- 倒计时button-->
        <com.xuexiang.xui.widget.button.CountDownButton
            android:id="@+id/bt_countdown4"
            style="@style/Button.Blue"
            android:text="获取验证码" />

        <com.xuexiang.xui.widget.button.switchbutton.SwitchButton
            android:id="@+id/sb_ios"
            style="@style/SwitchButtonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:swb_animationDuration="300"
            app:swb_backDrawable="@drawable/ios_back_drawable"
            app:swb_thumbDrawable="@drawable/ios_thumb_selector"
            app:swb_thumbMarginBottom="-8dp"
            app:swb_thumbMarginLeft="-5dp"
            app:swb_thumbMarginRight="-5dp"
            app:swb_thumbMarginTop="-2.5dp"
            app:swb_thumbRangeRatio="1.4" />


        <com.xuexiang.xui.widget.button.RippleView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="?attr/xui_config_content_spacing_horizontal"
            app:rv_type="simpleRipple">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:layout_marginStart="?attr/xui_config_content_spacing_horizontal"
                android:layout_marginEnd="?attr/xui_config_content_spacing_horizontal"
                android:background="@color/app_color_theme_1"
                android:gravity="center"
                android:text="单波纹"
                android:textColor="@color/xui_config_color_white"
                android:textSize="20sp" />

        </com.xuexiang.xui.widget.button.RippleView>

        <!-- 悬浮按钮-->
        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:layout_width="50dp"
            android:layout_height="50dp"
            app:borderWidth="10px"
            android:backgroundTint="@color/app_color_theme_4"
            app:rippleColor="@color/app_color_theme_3"
            />


        <com.xuexiang.xui.widget.button.SwitchIconView
            android:id="@+id/switchIconView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:padding="8dp"
            app:siv_disabled_alpha=".5"
            app:siv_disabled_color="#dadada"
            app:siv_enabled="true"
            app:siv_tint_color="#ffb700"

            app:srcCompat="@drawable/ic_camera" />



        <com.xuexiang.xui.widget.button.SmoothCheckBox
            android:id="@+id/scb"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_margin="5dp"
            android:paddingTop="10dp"
            app:scb_color_checked="@color/app_color_theme_1" />


        <com.xuexiang.xui.widget.button.shinebutton.ShineButton
            android:id="@+id/shine_button"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_gravity="center"
            app:sb_checked_color="#f26d7d"
            app:sb_icon_image="@drawable/ic_heart"
            app:sb_normal_color="@android:color/darker_gray" />

        <com.xuexiang.xui.widget.button.shinebutton.ShineButton
            android:id="@+id/shine_button_1"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_gravity="center"
            android:src="@android:color/darker_gray"
            app:sb_allow_random_color="false"
            app:sb_big_shine_color="#FF6666"
            app:sb_checked_color="#FF6666"
            app:sb_click_animation_duration="200"
            app:sb_enable_flashing="false"
            app:sb_icon_image="@drawable/ic_like"
            app:sb_normal_color="@android:color/darker_gray"
            app:sb_shine_animation_duration="1500"
            app:sb_shine_count="15"
            app:sb_shine_distance_multiple="1.5"
            app:sb_shine_turn_angle="10"
            app:sb_small_shine_color="#CC9999"
            app:sb_small_shine_offset_angle="20" />


    <!-- button xui-->
    <com.xuexiang.xui.widget.button.ButtonView
        android:id="@+id/buttonView"
        style="@style/ButtonView.Green"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginTop="237dp"
        android:layout_marginBottom="69dp"
        app:layout_constraintBottom_toTopOf="@+id/textView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />




    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

         </LinearLayout>

    </ScrollView>
</LinearLayout>

实例图: 

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


http://www.niftyadmin.cn/n/5199093.html

相关文章

#gStore-weekly | ​gAnswer源码分析:后处理

gAnswer通过自然语言问题转化成查询图&#xff0c;然后再和图数据库中的RDF图做匹配以生成用于查询的SPARQL语句。在将SPARQL语句应用于gStore查询之前还需要进行修复和聚合&#xff0c;以及一些后处理工作&#xff0c;本文聚焦于此。 // step 0: Node (entity & type &am…

C++数据结构:并查集

目录 一. 并查集的概念 二. 并查集的模拟实现 2.1 并查集类的声明 2.2 并查集的实现 三. 路径压缩 四. 总结 一. 并查集的概念 在生活中&#xff0c;我们经常需要对某一些事物进行归类处理&#xff0c;即&#xff1a;将N个不同的元素划分为几个互不相交的集合。在初始状态…

Java 中四种引用类型

Java 中有四种引用类型&#xff0c;分别是强引用、软引用、弱引用和虚引用。这四种引用类型在 Java 虚拟机中对对象的内存管理起着重要作用。以下是这四种引用类型的含义和区别&#xff1a; 强引用&#xff08;Strong Reference&#xff09;&#xff1a; 强引用是 Java 中最常…

el-tree 与table表格联动

html部分 <div class"org-left"><el-input v-model"filterText" placeholder"" size"default" /><el-tree ref"treeRef" class"filter-tree" :data"treeData" :props"defaultProp…

git 提交成了LFS格式,如何恢复

平常习惯使用sourceTree提交代码&#xff0c;某次打开时弹出了一个【是否要使用LFS提交】的确认弹窗&#xff0c;当时不知道LFS是什么就点了确认&#xff0c;后续提交时代码全变成了这个样子 因为是初始化的项目首次提交&#xff0c;将近四百个文件全被格式化成了这个样子&…

竞赛选题 行人重识别(person reid) - 机器视觉 深度学习 opencv python

文章目录 0 前言1 技术背景2 技术介绍3 重识别技术实现3.1 数据集3.2 Person REID3.2.1 算法原理3.2.2 算法流程图 4 实现效果5 部分代码6 最后 0 前言 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分享的是 &#x1f6a9; 深度学习行人重识别(person reid)系统 该项目…

科技的成就(五十三)

503、任天堂首次公开 Switch 2016 年 10 月 20 日&#xff0c;任天堂首次公开 Switch 正式名称及造型。Switch 是任天堂推出的混合型游戏机&#xff0c;可作为家用游戏机&#xff0c;也可作为便携式掌机。Switch 在开发过程中就以代号 NX 而闻名&#xff0c;成为当年的现象级产…

数据库系统原理与实践 笔记 #9

文章目录 数据库系统原理与实践 笔记 #9存储管理与索引文件和记录的组织文件组织定长记录变长记录分槽的页结构文件中记录的组织顺序文件组织多表聚簇文件组织 数据库系统原理与实践 笔记 #9 存储管理与索引 文件和记录的组织 文件组织 数据库是以一系列文件的形式存储的。…