Android开发返回键明暗点击效果的实例代码
作者:杭州小白 时间:2022-06-08 06:39:27
1:在很多APP里点击返回键,都可以看到返回键由亮变为暗
2:实现方法也是很简单的
(1)新建一个页面
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="#258aed"
>
//默认的ImageView没有可点击的属性,加入clickable添加点击属性
<ImageView
android:id="@+id/iv_back"
android:layout_width="55dp"
android:layout_height="55dp"
android:background="@drawable/iv_back_selector"
android:clickable="true"
/>
//layout_centerInParent文本居中
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="首页"
android:layout_centerInParent="true"
android:textColor="@color/white"
android:textSize="25sp"/>
</RelativeLayout>
(2)把需要的返回箭头图片添加到drawable,我的这两个图片是阿里巴巴图库标里下的
(3)在新建一个选择器,在drawable文件里新建iv_back_selector,代码入下,这样就实现了图片的明暗效果。
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/iv_back"
android:state_pressed="false"/>
<item android:drawable="@drawable/iv_back2"
android:state_pressed="true"/>
//选择器,不同情况下点击,选择对应的图片
</selector>
来源:https://blog.csdn.net/weixin_44941105/article/details/116077826
标签:Android,返回键,明暗点击
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Gradle属性设置及环境变量全面教程
2023-08-10 18:20:51
Android实现截图和分享功能的代码
2023-04-09 22:56:43
![](https://img.aspxhome.com/file/2023/8/106868_0s.png)
Springboot过滤器禁止ip频繁访问功能实现
2022-08-29 11:20:59
java base64编码、解码的三种方式总结
2022-12-29 22:20:51
解析Spring事件发布与监听机制
2022-09-01 09:52:19
![](https://img.aspxhome.com/file/2023/6/88586_0s.jpg)
Android 中SwipeRefreshLayout与ViewPager滑动事件冲突解决方法
2023-02-26 21:34:17
Android scrollToTop实现点击回到顶部(兼容PullTorefreshScrollview)
2021-07-29 09:06:37
![](https://img.aspxhome.com/file/2023/2/122102_0s.png)
C# BinaryReader实现读取二进制文件
2021-05-26 21:07:20
![](https://img.aspxhome.com/file/2023/6/75626_0s.gif)
C#实现抓取和分析网页类实例
2023-09-21 04:27:32
springboot-dubbo cannot be cast to问题及解决
2022-06-27 14:46:51
![](https://img.aspxhome.com/file/2023/0/75470_0s.png)
SpringBoot项目从搭建到发布一条龙
2023-11-21 09:28:44
![](https://img.aspxhome.com/file/2023/7/58847_0s.png)
java 教你如何给你的头像添加一个好看的国旗
2021-11-11 02:53:25
![](https://img.aspxhome.com/file/2023/1/84211_0s.jpg)
idea生成类注释和方法注释的正确方法(推荐)
2022-09-11 03:45:14
![](https://img.aspxhome.com/file/2023/4/85554_0s.jpg)
Java多线程 CompletionService
2022-08-19 18:51:32
基于java集合中的一些易混淆的知识点(详解)
2023-08-29 03:06:26
Java读取Map的两种方法与对比
2021-08-08 20:56:55
![](https://img.aspxhome.com/file/2023/3/65213_0s.png)
java 中的instanceof用法详解及instanceof是什么意思(推荐)
2023-06-07 13:52:27
Java设计模式七大原则之单一职责原则详解
2022-05-12 20:48:58
IDEA2020.1使用LeetCode插件运行并调试本地样例的方法详解
2022-02-28 09:44:47
![](https://img.aspxhome.com/file/2023/0/81190_0s.png)
一文详解Java中的Stream的汇总和分组操作
2021-12-24 17:32:54
![](https://img.aspxhome.com/file/2023/3/61313_0s.png)