当前位置: 首页 > news >正文

android 自定义SwitchCompat,Radiobutton,SeekBar样式

纯代码的笔记记录。

自定义SwitchCompat按钮的样式在这里插入图片描述

先自定义中间的圆球switch_thumb_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"><solid android:color="@color/white" /><sizeandroid:width="45dp"android:height="45dp" /><!-- 这里的5dp边距的作用是,圆点在轨道里面的边距,这样的效果感觉更好 --><strokeandroid:width="5dp"android:color="#00000000" /><corners android:radius="15dp" />
</shape>

然后自定义外部的椭圆

// switch_select_style.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@drawable/switch_selected" android:state_checked="true" /><item android:drawable="@drawable/switch_unselected" android:state_checked="false" />
</selector>// switch_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"><item ><shape android:shape="rectangle"><solid android:color="@color/home_color_sel" /><size android:height="40dp" /><corners android:radius="40dp" /><strokeandroid:width="1dp"android:color="@color/white" /></shape></item>
</layer-list>//switch_unselected.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"><item><shape android:shape="rectangle"><solid android:color="#2e4044" /><size android:height="40dp" /><strokeandroid:width="1dp"android:color="@color/white" /><corners android:radius="40dp" /></shape></item>
</layer-list>

然后编写控件

   <androidx.appcompat.widget.SwitchCompatandroid:id="@+id/sc_auto"android:textColor="@color/white"android:text=" ON/OFF"android:thumb="@drawable/switch_thumb_bg"app:switchMinWidth="@dimen/common_height"app:track="@drawable/switch_select_style"android:layout_width="match_parent"android:layout_height="@dimen/common_height"/>

自定义radioButton的选择背景色

在这里插入图片描述
编写drawable的样式

//radio_sel_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:state_checked="false"><shape android:shape="rectangle"><solid android:color="#323f45" /><strokeandroid:width="1dp"android:color="@color/white" /><cornersandroid:radius="99dp"/></shape></item><item android:state_checked="true"><shape android:shape="rectangle"><solid android:color="@color/home_color_sel" /><strokeandroid:width="1dp"android:color="@color/white" /><cornersandroid:radius="99dp"/></shape></item>
</selector>

编写控件

 <RadioButtonandroid:id="@+id/rb1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:button="@color/transparent"android:background="@drawable/radio_sel_bg"android:gravity="center"android:text="1s"android:checked="true"android:textColor="@color/white" /><RadioButtonandroid:id="@+id/rb2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:button="@color/transparent"android:background="@drawable/radio_sel_bg"android:gravity="center"android:text="1m"android:textColor="@color/white" />

自定义seekBar的拖动条样式

在这里插入图片描述
先自定义拖动球的样式

// icon_seek_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"><sizeandroid:width="40dp"android:height="30dp"/><solid android:color="@color/home_color_sel"/><cornersandroid:radius="10dp"/></shape>

然后编写拖动长条的样式

// bg_sb_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-listxmlns:android="http://schemas.android.com/apk/res/android"><item android:id="@android:id/background"><shape><-- 这里是拖动条右边的颜色 --><solid android:color="#2e4044" /></shape></item><item android:id="@android:id/secondaryProgress"><clip><shape><solid android:color="#FFFFFFFF" /></shape></clip></item><item android:id="@android:id/progress"><clip><shape><-- 这里是拖动条左边的颜色 --><solid android:color="#2e4044" /></shape></clip></item>
</layer-list>

编写控件

<SeekBarandroid:id="@+id/sb_brightness"android:layout_below="@+id/tv_music_num"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@color/transparent"android:maxHeight="10dp"android:minHeight="10dp"android:progress="50"android:max="255"android:min="0"android:thumb="@drawable/icon_seek_bg"android:progressDrawable="@drawable/bg_sb_bar"android:splitTrack="false" />

相关文章:

android 自定义SwitchCompat,Radiobutton,SeekBar样式

纯代码的笔记记录。 自定义SwitchCompat按钮的样式 先自定义中间的圆球switch_thumb_bg.xml <?xml version"1.0" encoding"utf-8"?> <shape xmlns:android"http://schemas.android.com/apk/res/android"android:shape"oval&q…...

计算机网络的定义与发展历程

计算机网络的定义 计算机网络是指通过通信设备和传输介质将分布在不同地点的计算机及其相关设备&#xff08;如打印机、服务器等&#xff09;连接起来&#xff0c;按照一定的通信协议进行数据交换与资源共享的系统。计算机网络的基本功能包括&#xff1a;信息的传输、资源共享…...

对比学习 (Contrastive Learning) 算法详解与PyTorch实现

对比学习 (Contrastive Learning) 算法详解与PyTorch实现 目录 对比学习 (Contrastive Learning) 算法详解与PyTorch实现1. 对比学习 (Contrastive Learning) 算法概述1.1 自监督学习1.2 对比学习的优势2. 对比学习的核心技术2.1 正样本对与负样本对2.2 对比损失函数2.3 数据增…...

DBeaver执行本地的sql语句文件避免直接在客户端运行卡顿

直接在客户端运行 SQL 语句和通过加载本地文件执行 SQL 语句可能会出现不同的性能表现&#xff0c;原因可能包括以下几点&#xff1a; 客户端资源使用&#xff1a; 当你在客户端界面直接输入和执行 SQL 语句时&#xff0c;客户端可能会消耗资源来维护用户界面、语法高亮、自动完…...

C++ 的 pair 和 tuple

1 std::pair 1.1 C 98 的 std::pair 1.1.1 std::pair 的构造 ​ C 的二元组 std::pair<> 在 C 98 标准中就存在了&#xff0c;其定义如下&#xff1a; template<class T1, class T2> struct pair;std::pair<> 是个类模板&#xff0c;它有两个成员&#x…...

Zookeeper 集群安装

Zookeeper 集群 主机 IP SoftWare Port OS Myidnode1 192.168.230.128 apache-zookeeper-3.7.1 2181 Centos 7 1 node2 192.168.230.129 apache-zookeeper-3.7.1...

git merge与rebase区别以及实际应用

在 Git 中&#xff0c;merge 和 rebase 是两种将分支的更改合并到一起的常用方法。虽然它们都可以实现类似的目标&#xff0c;但它们的工作方式和效果有所不同。 1. Git Merge 定义&#xff1a;git merge 是将两个分支的历史合并在一起的一种操作。当你执行 git merge 时&…...

kvm虚拟机出现应用程序无法正常启动报0xc0000142错误

场景&#xff1a;我的是window10虚拟机&#xff0c;在运行我的软件的时候&#xff0c;出现0xc0000142错误&#xff0c;原因可能是cpu型号问题&#xff0c;某些虚拟cpu可能没有特定的指令&#xff0c;只需要修改虚拟机配置文件以下参数即可...

Redis 安装与 Spring Boot 集成指南

安装 Redis 和将其与 Spring Boot 应用集成是构建高效缓存解决方案的常见步骤。以下是详细的指南&#xff0c;帮助你在本地环境中安装 Redis&#xff0c;并在 Spring Boot 项目中配置和使用它。 1. 安装 Redis Windows 环境 Redis 官方并不直接支持 Windows&#xff0c;但你…...

Flink集成TDEngine来批处理或流式读取数据进行流批一体化计算(Flink SQL)拿来即用的案例

Flink 以其流批一体化的编程模型而备受青睐。它支持高吞吐、低延迟的实时流计算,同时在批处理方面也表现出色。Flink 提供了丰富的 API,如 DataStream API 和 DataSet API,方便开发者进行数据处理操作,包括转换、聚合、连接等,使得开发者能够轻松构建复杂的数据处理逻辑。…...

【STM32】利用SysTick定时器定时1s

1.SysTick简单介绍 SysTick定时器是一个24位的倒计数定时器&#xff0c;当计数到0时&#xff0c;将从RELOAD寄存器中自动重装载定时初值&#xff0c;开始新一轮计数。 SysTick定时器用于在每隔一定的时间产生一个中断&#xff0c;即使在系统睡眠模式下也能工作。 关于SysTic…...

Python中的format格式化、填充与对齐、数字格式化方式

文章目录 一、format语法二、format格式化的用法2.1、按照先后顺序替换{}2.2、按照索引进行匹配替换{0}2.3、按关键字索引进行匹配替换2.4、通过列表索引格式化字符串2.5、使用元组2.6、通过字典设置格式化字符串2.7、混合使用 三、字符串填充与对齐3.1、左对齐及填充3.2、右对…...

winform第三方界面开源库AntdUI的使用教程保姆级环境设置篇

1. AntdUI 1.1. 导入项目 1.1.1. 首先新建一个空白的基于.net的Winfrom项目1.1.2. 复制AntdUI中src目录到我们的解决方案下面1.1.3. 解决方案下添加现有项目1.1.4. 添加项目引用 1.2. 编写代码 1.2.1. 改写Form1类&#xff0c;让其继承自public partial class Form1 : AntdUI.W…...

如何使用Yarn Workspaces实现Monorepo模式在一个仓库中管理多个项目

Yarn Workspaces是Yarn提供的一种依赖管理机制&#xff0c;它支持在单个代码仓库中管理多个包的依赖。这种机制非常适合需要多个相互依赖的包的项目&#xff0c;能够减少重复依赖&#xff0c;加快依赖安装速度&#xff0c;并简化依赖管理。下面将详细介绍如何使用Yarn Workspac…...

SpringCloud系列教程:微服务的未来(十一)服务注册、服务发现、OpenFeign快速入门

本篇博客将通过实例演示如何在 Spring Cloud 中使用 Nacos 实现服务注册与发现&#xff0c;并使用 OpenFeign 进行服务间调用。你将学到如何搭建一个完整的微服务通信框架&#xff0c;帮助你快速开发可扩展、高效的分布式系统。 目录 前言 服务注册和发现 服务注册 ​编辑 …...

物联网:七天构建一个闭环的物联网DEMO

我计划用七天的时间&#xff0c; 基于开源物联网平台&#xff0c; 打造一款物联网案例的闭环。 为了增加感观体验&#xff0c;欢迎大家与我保持亲密的沟通。 我们来看一段代码&#xff1a; Slf4j Component public class MqttSendManager {Resourceprivate MqttSendHandler m…...

景联文科技提供高质量多模态数据处理服务,驱动AI新时代

在当今快速发展的AI时代&#xff0c;多模态数据标注成为推动人工智能技术进步的关键环节。景联文科技作为行业领先的AI数据服务提供商&#xff0c;专注于为客户提供高质量、高精度的多模态数据标注服务&#xff0c;涵盖图像、语音、文本、视频及3D点云等多种类型的数据。通过专…...

c#13新特性

C# 13 即 .NET 9 按照计划会在2024年11月发布&#xff0c;目前一些新特性已经定型&#xff0c;让我们来预览一个比较大型比较重要的新特性。 正文 扩展类型 Extension types 在5月份的微软 Build 大会中的 What’s new in C# 13 会议上&#xff0c;两位大佬花了很长的篇幅来…...

LeetCode LCP17速算机器人

速算机器人&#xff1a;探索字符指令下的数字变换 在编程的奇妙世界里&#xff0c;我们常常会遇到各种有趣的算法问题&#xff0c;这些问题不仅考验我们的逻辑思维&#xff0c;还能让我们感受到编程解决实际问题的魅力。今天&#xff0c;就让我们一同探讨一个关于速算机器人的…...

杭州铭师堂的云原生升级实践

作者&#xff1a;升学e网通研发部基建团队 公司介绍 杭州铭师堂&#xff0c;是一个致力于为人的全面发展而服务的在线教育品牌。杭州铭师堂秉持“用互联网改变教育&#xff0c;让中国人都有好书读”的使命&#xff0c;致力于用“互联网教育”的科技手段让更多的孩子都能享有优…...

云计算——弹性云计算器(ECS)

弹性云服务器&#xff1a;ECS 概述 云计算重构了ICT系统&#xff0c;云计算平台厂商推出使得厂家能够主要关注应用管理而非平台管理的云平台&#xff0c;包含如下主要概念。 ECS&#xff08;Elastic Cloud Server&#xff09;&#xff1a;即弹性云服务器&#xff0c;是云计算…...

AtCoder 第409​场初级竞赛 A~E题解

A Conflict 【题目链接】 原题链接&#xff1a;A - Conflict 【考点】 枚举 【题目大意】 找到是否有两人都想要的物品。 【解析】 遍历两端字符串&#xff0c;只有在同时为 o 时输出 Yes 并结束程序&#xff0c;否则输出 No。 【难度】 GESP三级 【代码参考】 #i…...

LeetCode - 394. 字符串解码

题目 394. 字符串解码 - 力扣&#xff08;LeetCode&#xff09; 思路 使用两个栈&#xff1a;一个存储重复次数&#xff0c;一个存储字符串 遍历输入字符串&#xff1a; 数字处理&#xff1a;遇到数字时&#xff0c;累积计算重复次数左括号处理&#xff1a;保存当前状态&a…...

关于iview组件中使用 table , 绑定序号分页后序号从1开始的解决方案

问题描述&#xff1a;iview使用table 中type: "index",分页之后 &#xff0c;索引还是从1开始&#xff0c;试过绑定后台返回数据的id, 这种方法可行&#xff0c;就是后台返回数据的每个页面id都不完全是按照从1开始的升序&#xff0c;因此百度了下&#xff0c;找到了…...

基于Uniapp开发HarmonyOS 5.0旅游应用技术实践

一、技术选型背景 1.跨平台优势 Uniapp采用Vue.js框架&#xff0c;支持"一次开发&#xff0c;多端部署"&#xff0c;可同步生成HarmonyOS、iOS、Android等多平台应用。 2.鸿蒙特性融合 HarmonyOS 5.0的分布式能力与原子化服务&#xff0c;为旅游应用带来&#xf…...

服务器硬防的应用场景都有哪些?

服务器硬防是指一种通过硬件设备层面的安全措施来防御服务器系统受到网络攻击的方式&#xff0c;避免服务器受到各种恶意攻击和网络威胁&#xff0c;那么&#xff0c;服务器硬防通常都会应用在哪些场景当中呢&#xff1f; 硬防服务器中一般会配备入侵检测系统和预防系统&#x…...

Qwen3-Embedding-0.6B深度解析:多语言语义检索的轻量级利器

第一章 引言&#xff1a;语义表示的新时代挑战与Qwen3的破局之路 1.1 文本嵌入的核心价值与技术演进 在人工智能领域&#xff0c;文本嵌入技术如同连接自然语言与机器理解的“神经突触”——它将人类语言转化为计算机可计算的语义向量&#xff0c;支撑着搜索引擎、推荐系统、…...

镜像里切换为普通用户

如果你登录远程虚拟机默认就是 root 用户&#xff0c;但你不希望用 root 权限运行 ns-3&#xff08;这是对的&#xff0c;ns3 工具会拒绝 root&#xff09;&#xff0c;你可以按以下方法创建一个 非 root 用户账号 并切换到它运行 ns-3。 一次性解决方案&#xff1a;创建非 roo…...

ServerTrust 并非唯一

NSURLAuthenticationMethodServerTrust 只是 authenticationMethod 的冰山一角 要理解 NSURLAuthenticationMethodServerTrust, 首先要明白它只是 authenticationMethod 的选项之一, 并非唯一 1 先厘清概念 点说明authenticationMethodURLAuthenticationChallenge.protectionS…...

二维FDTD算法仿真

二维FDTD算法仿真&#xff0c;并带完全匹配层&#xff0c;输入波形为高斯波、平面波 FDTD_二维/FDTD.zip , 6075 FDTD_二维/FDTD_31.m , 1029 FDTD_二维/FDTD_32.m , 2806 FDTD_二维/FDTD_33.m , 3782 FDTD_二维/FDTD_34.m , 4182 FDTD_二维/FDTD_35.m , 4793...