软件编程
位置:首页>> 软件编程>> Android编程>> Android开发返回键明暗点击效果的实例代码

Android开发返回键明暗点击效果的实例代码

作者:杭州小白  发布时间:2022-06-08 06:39:27 

标签:Android,返回键,明暗点击

1:在很多APP里点击返回键,都可以看到返回键由亮变为暗

Android开发返回键明暗点击效果的实例代码
Android开发返回键明暗点击效果的实例代码

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,我的这两个图片是阿里巴巴图库标里下的

Android开发返回键明暗点击效果的实例代码

(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

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com