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

news2024/9/27 21:21:00

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

(点击 Sync Now 同步下)

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

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

(点击 Sync Now 同步下)

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.coloradmin.cn/o/1236048.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Centos8部署LNMP架构

LNMP架构 LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。L指Linux&#xff0c;N指Nginx&#xff0c;M一般指MySQL&#xff0c;也可以指MariaDB&#xff0c;P一般指PHP&#xff0c;也可以指Perl或Python。 1.Linux是一类Unix计算机操作系统的统称…

13 redis中的复制的拓扑结构

1、一主一从 为了性能考虑&#xff0c;主节点可以不开启AOF&#xff0c;但是要避免重启。 2、一主多从 适用于读操作的场景。由于从节点多&#xff0c;所以主的复制压力大 3、树状主从 数据先同步到redisB,redisC从节点C,E来看&#xff0c;redisB相当于主机了&#xff0c;可以…

微服务 Spring Cloud 8,开源RPC框架如何选型?

目录 一、开源RPC框架有哪些&#xff1f;1、跟语言平台绑定的开源RPC框架2、跨语言平台的开源RPC框架 二、跟语言平台绑定的开源RPC框架 -- Dubbo1、Dubbo的架构主要包含四个角色2、Dubbo的调用框架是如何实现的&#xff1f; 三、如何选择&#xff1f;四、跨语言平台的开源RPC框…

Linux shell编程学习笔记27:tput

除了stty命令&#xff0c;我们还可以使用tput命令来更改终端的参数和功能。 1 tput 命令的功能 tput 命令的主要功能有&#xff1a;移动更改光标、更改文本显示属性&#xff08;如颜色、下划线、粗体&#xff09;&#xff0c;清除屏幕特定区域等。 2 tput 命令格式 tput [选…

基于SSM的校园活动资讯网设计与实现

末尾获取源码 开发语言&#xff1a;Java Java开发工具&#xff1a;JDK1.8 后端框架&#xff1a;SSM 前端&#xff1a;Vue 数据库&#xff1a;MySQL5.7和Navicat管理工具结合 服务器&#xff1a;Tomcat8.5 开发软件&#xff1a;IDEA / Eclipse 是否Maven项目&#xff1a;是 目录…

OceanBase:OBServer节点管理

目录 1.查看节点 2.添加节点 2.1 创建数据目录 2.2.OceanBase 运行时所依赖的部分三方动态库 2.3.安装 OceanBase 数据库的 RPM 包 2.4.启动节点 observer 进程 2.5.向集群中添加节点 3.隔离节点 4.重启节点 4.1 停止服务 4.2 转储 4.3 关闭进程 4.4 启动进程 4.…

单体进化微服务:拆分、注册、调用、网关、过滤、治理、分布式事务

这里写目录标题 基本介绍生产-消费-网关父依赖生产者服务消费者服务网关服务common服务 感想 基本介绍 Spring Cloud 是一个用于构建分布式系统和微服务架构的开发工具包。它提供了一系列的功能和组件&#xff0c;用于解决微服务架构中的常见问题&#xff0c;如服务注册与发现…

Python---函数的应用案例(多个)

案例&#xff1a;使用print方法打印一条横线 print(- * 40) 案例&#xff1a;对上个案例进行升级&#xff0c;可以根据输入的num数值&#xff0c;生成指定数量的横线 def print_lines(num, length):""" print_lines函数主要作用用于生成多条指定长度的横线&…

Windows安装MongoDB

1、下载MongoDB的zip&#xff0c;解压 2、创建目录 mkdir D:\JavaSoftware\Database\MongoDB\mongodb-win32-x86_64-windows-5.0.8\data\db mkdir D:\JavaSoftware\Database\MongoDB\mongodb-win32-x86_64-windows-5.0.8\data\log 3、创建一个配置文件mongod.cfg&#xff0c…

【JavaEE】Servlet实战案例:表白墙网页实现

一、功能展示 输入信息&#xff1a; 点击提交&#xff1a; 二、设计要点 2.1 明确前后端交互接口 &#x1f693;接口一&#xff1a;当用户打开页面的时候需要从服务器加载已经提交过的表白数据 &#x1f693;接口二&#xff1a;当用户新增一个表白的时候&#xff0c;…

Self-Supervised Exploration via Disagreement论文笔记

通过分歧进行自我监督探索 0、问题 使用可微的ri直接去更新动作策略的参数的&#xff0c;那是不是就不需要去计算价值函数或者critic网络了&#xff1f; 1、Motivation 高效的探索是RL中长期存在的问题。以前的大多数方式要么陷入具有随机动力学的环境&#xff0c;要么效率…

1.Qt5.15及其以上的下载

Qt5.15及其以上的下载 简介&#xff1a; ​ Qt是一个跨平台的C库&#xff0c;允许开发人员创建在不同操作系统&#xff08;如Windows、macOS、Linux/Unix&#xff09;和设备上具有本地外观和感觉的应用程序。Qt提供了一套工具和库&#xff0c;用于构建图形用户界面&#xff0…

C语言基础---函数、数组

目录 一、函数 二、数组​ 一、函数 交换两个数&#xff1a; 发现这样并没有交换a和b的值&#xff0c;只是交换了x和y的值&#xff0c;这是因为&#xff1a; //当实参传递给形参的时候&#xff0c;形参是实参的一份临时拷贝 //对形参的修改不能改变实参 实参与形参是…

linux高性能服务器

第一部分、TCP/IP协议详解 TCP协议为应用层提供可靠的、面向连接的和基于流的服务 可靠 使用超时重传(发送端在发送报文后启动一个定时器&#xff0c;若定时器在规定时间内没有收到应答就会重发该报文)&#xff0c;发送应答机制(发送端发送的每个TCP报文都必须得到接收方的应答…

城市易涝点怎么安装万宾科技内涝积水监测仪?

城市内涝是多个城市广泛存在的问题&#xff0c;经常给城市的居民和基础设施带来一些安全威胁。暴雨引发的道路积水和交通中断、财产损失&#xff0c;甚至公共安全威胁都是城市管理者需要提前预防的问题。为了解决这些问题&#xff0c;内涝积水监测仪的应用是一大重要的举措&…

机器视觉兄弟们,新工作之前,不要过度准备

大家对工作的渴望我感同身受&#xff0c;有人去机器视觉培训机构培训&#xff0c;有人默默无闻地努力学习&#xff0c;不都是为了一份高新好工作吗&#xff1f; 实际上是&#xff1a; 技术高的人&#xff0c;劳动力贬值。 技术低的人&#xff0c;没有生存空间。 你有野心&…

linux 开发板以太网通过Ubuntu上外网方法

在开发板嵌入式设备&#xff0c;有一个mgbe网卡&#xff0c;用网线与连接soc的网卡&#xff0c;和外接网卡&#xff0c;将网卡usb接口插入电脑&#xff0c;选择接入到Ubuntu系统 在Ubuntu将能识别到这个外接网卡&#xff0c;这样就可以通过Ubuntu和soc通讯了&#xff0c; 如下…

关于标准库中的string类 - c++

目录 关于string类 string类的常用接口 string类常用接口的简单模拟实现 关于string类 string类在cplusplus.com的文档介绍 1. string是表示字符串的字符串类 2. 该类的接口与常规容器的接口基本相同&#xff0c;再添加了一些专门用来操作string的常规操作。 3. string在…

SEO与 SMO 的区别

SEO和SMO都是为网站带来流量的方法&#xff0c;但二者截然不同。搜索引擎优化&#xff08;SEO&#xff09;是一种在搜索引擎结果页面上提高网站流量的技术&#xff0c;而社交媒体优化&#xff08;SMO&#xff09;则是一种让更多用户看到社交媒体内容的技术。 阅读本文&#xf…

开源之夏2023 MatrixOne 项目结业啦

开源之夏是由中国科学院软件研究所与 OpenEuler 社区共同主办的一项面向高校学生的暑期在线活动&#xff0c;旨在鼓励在校学生积极参与开源软件的开发维护&#xff0c;促进优秀开源软件社区的蓬勃发展。 在开源之夏 2023 年中&#xff0c;MatrixOne 一共有 2 个任务项目&#…