当前位置: 首页 > 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;致力于用“互联网教育”的科技手段让更多的孩子都能享有优…...

一键永久珍藏QQ空间回忆:GetQzonehistory完整备份指南

一键永久珍藏QQ空间回忆&#xff1a;GetQzonehistory完整备份指南 【免费下载链接】GetQzonehistory 获取QQ空间发布的历史说说 项目地址: https://gitcode.com/GitHub_Trending/ge/GetQzonehistory 你是否担心QQ空间里的珍贵回忆会随着时间流逝而消失&#xff1f;那些记…...

Kazumi:开源动漫聚合工具如何重塑你的追番体验

Kazumi&#xff1a;开源动漫聚合工具如何重塑你的追番体验 【免费下载链接】Kazumi 基于自定义规则的番剧采集APP&#xff0c;支持流媒体在线观看&#xff0c;支持弹幕&#xff0c;支持实时超分辨率。 项目地址: https://gitcode.com/gh_mirrors/ka/Kazumi 在数字娱乐爆…...

幻兽帕鲁存档修复终极指南:告别数据丢失的完整解决方案

幻兽帕鲁存档修复终极指南&#xff1a;告别数据丢失的完整解决方案 【免费下载链接】palworld-host-save-fix Fixes the bug which forces a player to create a new character when they already have a save. Useful for migrating maps from co-op to dedicated servers and…...

LightOnOCR-2-1B实战体验:上传图片,秒出文字,简单高效

LightOnOCR-2-1B实战体验&#xff1a;上传图片&#xff0c;秒出文字&#xff0c;简单高效 1. 从“想法”到“文字”&#xff0c;只需要三步 你有没有过这样的经历&#xff1f;手机拍了一张会议白板的照片&#xff0c;想把上面的要点整理成文档&#xff0c;结果对着照片一个字…...

BilibiliDown:三步实现B站音频高效提取与批量处理全攻略

BilibiliDown&#xff1a;三步实现B站音频高效提取与批量处理全攻略 【免费下载链接】BilibiliDown (GUI-多平台支持) B站 哔哩哔哩 视频下载器。支持稍后再看、收藏夹、UP主视频批量下载|Bilibili Video Downloader &#x1f633; 项目地址: https://gitcode.com/gh_mirrors…...

Unity坐标变换笔记

屏幕uv坐标计算方法&#xff1a; 顶点着色器&#xff1a; float4 positionCS : SV_POSITION; //表示裁剪空间下的坐标&#xff1b; float4 ndc input.positionCS * 0.5f; input.positionNDC.xy float2(ndc.x, ndc.y * _ProjectionParams.x) ndc.w; input.positionNDC.zw …...

不同海外市场,跨境电商AI搜索优化有何差异?

跨境电商的核心特点是“面向全球市场”&#xff0c;而不同海外市场的语言习惯、搜索逻辑、消费场景、采购需求差异巨大&#xff0c;这就决定了AI搜索优化不能“一刀切”&#xff0c;需要结合不同市场的特性&#xff0c;制定差异化的优化策略。很多企业之所以优化效果不佳&#…...

3个核心方案:用UNTRUNC工具修复损坏视频的专业指南

3个核心方案&#xff1a;用UNTRUNC工具修复损坏视频的专业指南 【免费下载链接】untrunc Restore a damaged (truncated) mp4, m4v, mov, 3gp video. Provided you have a similar not broken video. 项目地址: https://gitcode.com/gh_mirrors/unt/untrunc 价值定位&am…...

2026年Turnitin AI检测对留学生论文的影响:检测标准和应对方案

2026年Turnitin AI检测对留学生论文的影响&#xff1a;检测标准和应对方案 同一篇论文&#xff0c;知网52%&#xff0c;维普38%&#xff0c;万方21%。 为什么差这么多&#xff1f;不是平台乱搞&#xff0c;而是检测算法和判断标准不一样。理解了Turnitin AI检测背后的逻辑&am…...

【架构实战】读写分离中间件对比(ShardingSphere/MyCat)

一、为什么需要读写分离 在大多数互联网应用中&#xff0c;读操作远多于写操作&#xff1a; 读请求&#xff1a;70-80% 写请求&#xff1a;20-30%单机数据库的问题&#xff1a; 主库&#xff1a;处理所有写请求 部分读请求↓ 连接池耗尽 → 响应变慢 → 用户投诉解决方案&a…...