美文网首页
安卓设置按钮点击变色,初始背景透明

安卓设置按钮点击变色,初始背景透明

作者: 心中有梦丶身边有你 | 来源:发表于2018-12-08 15:49 被阅读0次

首先在res的drawable文件夹下新建一个文件夹shape

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/clr_normal"
        android:state_pressed="false"/>
    <item android:drawable="@drawable/clr_pressed"
        android:state_pressed="true"/>

</selector>

在values的strings文件夹中添加

<drawable name="clr_normal">#10000000</drawable>  
<drawable name="clr_pressed">#32000000</drawable>
//一共是8位16进制数,其中后面6位是颜色的RGB值。前面两位是颜色透明的数值,值越小,就越透明。

最后在你的组件上引用就行了

android:background="@drawable/shape"

相关文章

网友评论

      本文标题:安卓设置按钮点击变色,初始背景透明

      本文链接:https://www.haomeiwen.com/subject/ozpqhqtx.html