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>  
  • 相关阅读:
    jython resources
    Installing a Library of Jython ScriptsPart of the WebSphere Application Server v7.x Administration Series Series
    jython好资料
    ulipad install on 64bit win7 has issue
    an oracle article in high level to descibe how to archtichre operator JAVA relevet project
    table的宽度,单元格内换行问题
    Linux常用命令大全
    dedecms系统后台登陆提示用户名密码不存在
    登录织梦后台提示用户名不存在的解决方法介绍
    Shell常用命令整理
  • 原文地址:https://www.cnblogs.com/AganRun/p/8118645.html
Copyright © 2011-2022 走看看