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

Kotlin语言实现单击任意TextVIew切换一个新页面,并且实现颜色变换

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:orientation="vertical"android:layout_height="match_parent"><!-- 这里放置你的其他视图组件 --><RadioGroupandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><RadioButtonandroid:id="@+id/textView1"android:layout_width="wrap_content"android:button="@null"android:textColor="@color/color"android:checked="true"android:layout_marginHorizontal="20dp"android:layout_height="wrap_content"android:text="First TextView"android:clickable="true" /><RadioButtonandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_marginHorizontal="20dp"android:button="@null"android:layout_height="wrap_content"android:text="Second TextView"android:textColor="@color/color"android:clickable="true"android:layout_below="@id/textView1" /><!-- 更多的 TextView 组件 -->
</RadioGroup><FrameLayoutandroid:id="@+id/container"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_below="@id/textView2" /></LinearLayout>

创建一个新包 color

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/purple_700" android:state_checked="true"/><item android:color="@color/black" android:state_checked="false"/>
</selector>

功能页

class MainActivity2 : AppCompatActivity() {private lateinit var fragmentManager: FragmentManagerprivate val binding by lazy {ActivityMain2Binding.inflate(layoutInflater)}override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(binding.root)fragmentManager = supportFragmentManagerbinding.textView1.setOnClickListener {replaceFragment(HomeFragment())}binding.textView2.setOnClickListener {replaceFragment(SecondFragment())}}private fun replaceFragment(fragment: Fragment) {val transaction: FragmentTransaction = fragmentManager.beginTransaction()transaction.replace(R.id.container, fragment)transaction.addToBackStack(null)transaction.commit()}
}

相关文章:

  • 基础组件-流量回放(全链路流量回放预研)
  • k8s-集群升级 2
  • 【OpenCV实现图像:OpenCV进行OCR字符分割】
  • C语言 原码、反码、补码
  • MySQL 定时计划任务 事件的使用
  • 蓝桥杯第三周算法竞赛D题E题
  • 导航守卫有哪三种?
  • jenkins+centos7上传发布net6+gitlab
  • C++单调向量算法:132 模式解法三枚举1
  • 【每日一题】—— C. Yarik and Array(Codeforces Round 909 (Div. 3))(贪心)
  • 【具身智能评估1】具身视觉语言规划(EVLP)仿真环境汇总
  • Vulkan渲染引擎开发教程 一、开发环境搭建
  • python基础练习题库实验3
  • Canal+Kafka实现MySQL与Redis数据同步(一)
  • 贪吃蛇小游戏
  • 时间复杂度分析经典问题——最大子序列和
  • 30天自制操作系统-2
  • angular2开源库收集
  • JavaScript类型识别
  • JavaSE小实践1:Java爬取斗图网站的所有表情包
  • js
  • log4j2输出到kafka
  • miniui datagrid 的客户端分页解决方案 - CS结合
  • mongo索引构建
  • Redis提升并发能力 | 从0开始构建SpringCloud微服务(2)
  • 基于OpenResty的Lua Web框架lor0.0.2预览版发布
  • 解决jsp引用其他项目时出现的 cannot be resolved to a type错误
  • 开源地图数据可视化库——mapnik
  • 爬虫模拟登陆 SegmentFault
  • 如何借助 NoSQL 提高 JPA 应用性能
  • 软件开发学习的5大技巧,你知道吗?
  • 三栏布局总结
  • 探索 JS 中的模块化
  • 主流的CSS水平和垂直居中技术大全
  • No resource identifier found for attribute,RxJava之zip操作符
  • puppet连载22:define用法
  • # MySQL server 层和存储引擎层是怎么交互数据的?
  • # 深度解析 Socket 与 WebSocket:原理、区别与应用
  • #{}和${}的区别是什么 -- java面试
  • (10)ATF MMU转换表
  • (Redis使用系列) Springboot 实现Redis 同数据源动态切换db 八
  • (附源码)计算机毕业设计ssm高校《大学语文》课程作业在线管理系统
  • (论文阅读30/100)Convolutional Pose Machines
  • (三)Pytorch快速搭建卷积神经网络模型实现手写数字识别(代码+详细注解)
  • (算法)前K大的和
  • (学习日记)2024.03.25:UCOSIII第二十二节:系统启动流程详解
  • (中等) HDU 4370 0 or 1,建模+Dijkstra。
  • (转)Oracle存储过程编写经验和优化措施
  • ***检测工具之RKHunter AIDE
  • .NET Core、DNX、DNU、DNVM、MVC6学习资料
  • .net 程序 换成 java,NET程序员如何转行为J2EE之java基础上(9)
  • .net图片验证码生成、点击刷新及验证输入是否正确
  • .NET中GET与SET的用法
  • ?php echo $logosrc[0];?,如何在一行中显示logo和标题?
  • @KafkaListener注解详解(一)| 常用参数详解