温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android利用drawable文件夹自定义控件背景、样式

发布时间:2020-07-02 22:34:15 来源:网络 阅读:461 作者:focus_000 栏目:移动开发

<SPAN COLOR: ">一.自定义控件的选中效果

在drawable文件夹下新建selector类型的xml文件(右键drawable,选择新建android xml file),文件名任意,内容如:

<?xml version="1.0" encoding="utf-8">
  xmlns:android="http://schemas.android.com/apk/res/android">
   
   
   
   

?xml>

/*state_focused表示是否是非触摸状态,true表示是非触摸状态。其中android:drawable可以引用drawable文件夹下其它资源文件,比如shape资源,用来实现控件常规、按下、选中等样式*。

使用方法:在布局文件中,控件的背景属性中引用这些资源,以下类同*/

 

<SPAN COLOR: ">二.自定义控件的外观

新建shape类型的xml文件,如:

<?xml version="1.0" encoding="utf-8">
?xml>

           android:width="1px"
        android:color="@color/color_black" />

           android:bottom="3dp"
        android:left="3dp"
        android:right="3dp"
        android:top="3dp" />
           android:color="@color/color_white"
        />

           android:bottomLeftRadius="0dp"
        android:bottomRightRadius="0dp"
        android:radius="1dp"
        android:topLeftRadius="@dimen/indicator_corner_radius"
        android:topRightRadius="@dimen/indicator_corner_radius" />

 

/*

stroke表示描边

padding内边距

solid表示实体,即控件的整体区域

corners表示圆角

*/

<SPAN COLOR: ">三.多样式叠加

新建layer-list类型的xml文件,如:

<?xml version="1.0" encoding="UTF-8">
?xml>

   
       
           

           

                           android:width="1dp"
                android:color="@color/stroke" />
       
   
   
                   android:scaleGravity="center"
            android:scaleHeight="5dp"
            android:scaleWidth="5dp" />
   

 

 

<SPAN COLOR: ">综合示例:

<?xml version="1.0" encoding="UTF-8">  
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" >
 
     
         
             
           <gradient android:startColor="#ff707070" 
                android:centerColor="#ff707070" android:endColor="#ff707070" 
                android:centerY="1" android:angle="270" />     
         
     ?xml>

    
        
            
                
                                         android:startColor="#ffaaa9a7"
                         android:centerColor="#ffaaa9a7"
                         android:centerY="1"
                         android:endColor="#ffaaa9a7"
                         android:angle="270"
                 />
            

        
    
    
      
         
             
                 
               <gradient android:startColor="#ffA90101" 
                    android:centerColor="#ffA90101" android:endColor="#ffA90101" 
                    android:centerY="1" android:angle="270" />     
             
         
     
   

 

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI