zoukankan      html  css  js  c++  java
  • Android 使用shape定义不同控件的的颜色、背景色、边框色

    Android 使用shape定义不同控件的的颜色、背景色、边框色

    设置按钮的右边框和底边框颜色为红色,边框大小为3dp:

    在drawable新建一个 buttonstyle.xml的文件,内容如下:

    <?xml version="1.0" encoding="UTF-8"?>  
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">   
    <!-- 连框颜色值 --><item>   
          <shape>   
                <solid android:color="#ff0000" />   
          </shape>   
    </item>   
    <!-- 主体背景颜色值 -->  
    <item android:bottom="3dp" android:right="3dp">   
         <shape>   
               <solid android:color="#ffffff" />  
                 
               <padding android:bottom="10dp"  
                    android:left="10dp"  
                    android:right="10dp"  
                    android:top="10dp" />  
         </shape>       
    </item>  
    </layer-list> 

    然后在布局文件里面的Button里面设置如下:

    <Button  
       android:id="@+id/button1"  
       android:layout_width="wrap_content"  
       android:layout_height="wrap_content"  
       android:text="Button1"  
       android:background="@drawable/buttonstyle" />  

    android shape的使用
    shape用于设定形状,可以在selector,layout等里面使用,有6个子标签,各属性如下:

    <?xml version="1.0" encoding="utf-8"?>  
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >  
          
        <!-- 圆角 -->  
        <corners  
            android:radius="9dp"  
            android:topLeftRadius="2dp"  
            android:topRightRadius="2dp"  
            android:bottomLeftRadius="2dp"  
            android:bottomRightRadius="2dp"/><!-- 设置圆角半径 -->  
          
        <!-- 渐变 -->  
        <gradient  
            android:startColor="@android:color/white"  
            android:centerColor="@android:color/black"  
            android:endColor="@android:color/black"  
            android:useLevel="true"  
            android:angle="45"  
            android:type="radial"  
            android:centerX="0"  
            android:centerY="0"  
            android:gradientRadius="90"/>  
          
        <!-- 间隔 -->  
        <padding  
            android:left="2dp"  
            android:top="2dp"  
            android:right="2dp"  
            android:bottom="2dp"/><!-- 各方向的间隔 -->  
          
        <!-- 大小 -->  
        <size  
            android:width="50dp"  
            android:height="50dp"/><!-- 宽度和高度 -->  
          
        <!-- 填充 -->  
        <solid  
            android:color="@android:color/white"/><!-- 填充的颜色 -->  
          
        <!-- 描边 -->  
        <stroke  
            android:width="2dp"  
            android:color="@android:color/black"  
            android:dashWidth="1dp"  
            android:dashGap="2dp"/>  
          
    </shape>  
  • 相关阅读:
    TCP/IP(三)数据链路层~2
    TCP/IP(三)数据链路层~1
    TCP/IP(二)物理层详解
    Maven(六)之依赖管理
    RAID : 独立磁盘冗余阵列(Redundant Array of Independent Disks)
    Oracle启动两个监听
    Oracle服务器修改IP后
    su: cannot set user id: Resource temporarily unavailable
    hadoop报错:java.io.IOException(java.net.ConnectException: Call From xxx/xxx to xxx:10020 failed on connection exception: java.net.ConnectException: 拒绝连接
    spring boot 实现mybatis拦截器
  • 原文地址:https://www.cnblogs.com/AganRun/p/8118645.html
Copyright © 2011-2022 走看看