zoukankan      html  css  js  c++  java
  • Button 自定义(一)-shape

    需求:自定义Button,使用系统自定义Shape;

    效果图:

    1.默认状态

    2.选中状态

    实现分析:

    1.目录结构:

    代码实现:

    1.button_normal.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <solid android:color="#ff007aff" />
    
        <corners
            android:bottomLeftRadius="6dp"
            android:bottomRightRadius="6dp"
            android:topLeftRadius="6dp"
            android:topRightRadius="6dp" />
    
    </shape>

    2.button_select.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
        <solid android:color="#FFD700" />
    
        <corners
            android:bottomLeftRadius="6dp"
            android:bottomRightRadius="6dp"
            android:topLeftRadius="6dp"
            android:topRightRadius="6dp" />
    
    </shape>

    solid:实心,就是填充的意思

    corners:圆角
    android:radius为角的弧度,值越大角越圆。

    3.button_selector.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:drawable="@drawable/button_select" android:state_focused="true"></item>
        <item android:drawable="@drawable/button_select" android:state_pressed="true"></item>
        <item android:drawable="@drawable/button_normal" android:state_focused="false" android:state_pressed="false"></item>
        <item android:drawable="@drawable/button_normal" ></item>
    
    </selector>

    4.fragment_main.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.jjc.demo.MainActivity$PlaceholderFragment" >
    
        <Button
            android:id="@+id/button_test"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/button_selector"
            android:text="推荐组合"
            android:textColor="@android:color/white" />
    
    </RelativeLayout>

    代码:http://pan.baidu.com/s/1ntBN5Df

  • 相关阅读:
    C#图片无损压缩
    as3.0 动态文本属性大全
    卡​马​克​卷​轴​算​法​研​究​_​地​图​双​缓​冲
    春卷活动心得
    移动端videojs视频插件使用直播流rtmp、hls、http-flv的注意事项
    在Windows2008系统中利用IIS建立FTP服务器
    winform 窗体自适应 根据新窗体大小按比例放缩
    HTTPS抓包
    数据库 事物 锁
    sql 事物 锁 快照(转发的,写的非常好)
  • 原文地址:https://www.cnblogs.com/sishuiliuyun/p/3948962.html
Copyright © 2011-2022 走看看