zoukankan      html  css  js  c++  java
  • Android碎笔录2——按键的点击变色和圆角实现

    android的Button默认写出来之后都是方形的直角,并且点击感很不明显,只要在drawable中加上一个xml就能解决这个问题:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:state_pressed="true"> //点击时的样子
            <shape android:shape="rectangle">  //显示为方形
                <corners  //显示为圆角
                    android:topLeftRadius="8dip"
                    android:topRightRadius="8dip"
                    android:bottomLeftRadius="8dip"
                    android:bottomRightRadius="8dip"/>
                <solid android:color="@color/darkred"/>  //背景颜色
            </shape>
        </item>
        <item android:state_pressed="false">  //没点击时的样子
            <shape android:shape="rectangle">
                <corners
                    android:topLeftRadius="8dip"
                    android:topRightRadius="8dip"
                    android:bottomLeftRadius="8dip"
                    android:bottomRightRadius="8dip"/>
                <solid android:color="@color/red"/>
            </shape>
        </item>
    </selector>

    我的xml命名是background_shape.xml,去掉我写的注释就直接能用,用法是在Button中加上:

    android:background="@drawable/backguound_shape"

    这样就能完成了。

  • 相关阅读:
    python(打印九九乘法表,三角形)
    Python (内置函数)
    python (生成器,生成推导式)
    python (函数名,闭包和迭代器)
    python (函数命名空间和作用域)
    python (函数)
    python (文件)
    python (集合和深浅拷贝)
    jquery 学习(四)
    JavaScript练习
  • 原文地址:https://www.cnblogs.com/yuanxixing/p/9155558.html
Copyright © 2011-2022 走看看