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

Android:ImageView xml方式配置selector 图片切换

1、在res/drawable目录下创建一个新的XML文件,比如selector_image.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 背景选择器
state_pressed  按下
state_focused 获得焦点
默认 图片
-->
   
<item android:state_pressed="true" android:drawable="@drawable/image_pressed" />

            <item android:state_focused="true" android:drawable="@drawable/image_pressed" />

             <item android:drawable="@drawable/image_normal" />


</selector>

2、在布局文件中使用这个Selector图片资源作为ImageView的src属性即可。例如,可以在ImageView的XML布局中添加android:src="@drawable/selector_image"来引用这个Selector图片资源。

<ImageView
        android:clickable="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/selector_image"
        />

http://www.lryc.cn/news/101672.html

相关文章:

  • Spring Boot 缓存 Cache 入门
  • 如何关闭谷歌浏览器自动更新
  • mybatis日志工厂
  • 020 - STM32学习笔记 - Fatfs文件系统(二) - 移植与测试
  • flask用DBUtils实现数据库连接池
  • SQL注入之布尔盲注
  • 微服务入门---SpringCloud(一)
  • Rust vs Go:常用语法对比(九)
  • Typescript 第五章 类和接口(多态,混入,装饰器,模拟final,设计模式)
  • IFNULL()COALESCE()
  • WPF实战学习笔记23-首页添加功能
  • OpenCV-Python常用函数汇总
  • Vue-router多级路由
  • 前端学习--vue2--2--vue指令基础
  • 【Python机器学习】实验03 logstic回归
  • 面试-杨辉三角python递归实现,二进制转换
  • SPEC CPU 2017 x86_64 Ubuntu 22.04 LTS LLVM 16.0.6 编译 intrate intspeed
  • java备忘录模式
  • iOS--runtime
  • 06. 管理Docker容器数据
  • 计算机视觉常用数据集介绍
  • Arcgis画等高线
  • abp vnext4.3版本托管到iis同时支持http和https协议
  • 2023年全网电视盒子无线ADB修改桌面(无需ROOT)
  • 什么是Java中的Maven?
  • 【C++】总结7
  • 【前端知识】React 基础巩固(四十二)——React Hooks的介绍
  • adb命令丨adb push命令大全_adb操控手机和指令
  • 【腾讯云 Cloud Studio 实战训练营】沉浸式体验编写一个博客系统
  • 手机视频聊天分享