在drawable下创建bg.xml文件

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:andro>
<item android:state_pressed="true" android:drawable="@color/grey"></item>
<item android:drawable="@color/white2"></item>
</selector>

  

在res/values/colors.xml文件中

<color name="white2">#FFFFFF</color>
<color name="grey">#D1D1D1</color>

  


在布局文件中
android:background="@drawable/bg"
不过在这里要注意的是,如果你的这个RelativeLayout在代码中有设置点击事件,那么这样效果是没问题的。
但是如果在代码中没有设置点击事件,那么在布局文件中要加一句

android:clickable="true"

  



相关文章:

  • 2021-11-21
  • 2022-12-23
  • 2021-12-19
  • 2021-08-04
  • 2022-02-07
  • 2021-05-31
  • 2021-11-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-11
  • 2021-09-11
  • 2021-06-14
  • 2021-08-19
  • 2022-02-28
相关资源
相似解决方案