【自用】Android Button 点击效果 selector

 XML:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:tools="http://schemas.android.com/tools" 
          xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/color_3721"/>
    <item android:drawable="@color/color_3927" tools:ignore="StateListReachable" />
</selector>

文件:res/drawable/xxxx.xml

PS: 告诉你们一个秘密,这两个<item>的顺序是不能颠倒的。

一些我常用到的 colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#00aa33</color>
    <color name="colorPrimaryDark">#00aa33</color>
    <color name="colorAccent">#FF4081</color>

    <color name="black_overlay">#66000000</color>
    <color name="bule_1">#33b5e5</color>
    <color name="blue_2">#195a72</color>
    <color name="green_1">#00aa33</color>
    <color name="green_2">#005519</color>
    <color name="orange_1">#ff8800</color>
    <color name="orange_2">#7f4400</color>
    <color name="red_1">#ff4444</color>
    <color name="red_2">#7f2222</color>
    <color name="yellow_1">#ffbb33</color>
    <color name="yellow_2">#7f5d19</color>
</resources>

 

    PS:自用的  不做解释                        作者:一个吃货帅锅    

转载于:https://my.oschina.net/kilosnow/blog/912377

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android Button点击动画可以通过设置Button的背景来实现。具体步骤如下: 1. 在drawable文件夹下创建一个selector.xml文件,用于设置Button的不同状态下的背景。 2. 在selector.xml文件中设置Button的不同状态下的背景,例如: ``` <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_pressed" android:state_pressed="true"/> <item android:drawable="@drawable/button_normal"/> </selector> ``` 3. 在Button的布局文件中设置Button的背景为selector.xml文件,例如: ``` <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:background="@drawable/selector"/> ``` 4. 在Button点击事件中设置点击动画,例如: ``` button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.button_click); button.startAnimation(animation); } }); ``` 其中,button_click.xml文件为点击动画的动画文件,例如: ``` <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:fromXScale="1." android:toXScale=".9" android:fromYScale="1." android:toYScale=".9" android:pivotX="50%" android:pivotY="50%" android:duration="100"/> <scale android:fromXScale=".9" android:toXScale="1." android:fromYScale=".9" android:toYScale="1." android:pivotX="50%" android:pivotY="50%" android:startOffset="100" android:duration="100"/> </set> ``` 这样就可以实现Button点击动画了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值