首页 > 系统 > Android > 正文

Android编程实现改变控件背景及形态的方法

2019-10-24 20:24:16
字体:
来源:转载
供稿:网友
这篇文章主要介绍了Android编程实现改变控件背景及形态的方法,涉及Android控件布局设置的相关技巧,需要的朋友可以参考下
 

本文实例讲述了Android编程实现改变控件背景及形态的方法。分享给大家供大家参考,具体如下:

1. 改变背景

在res/drawable下创建一个xml文件:

<?xml version="1.0" encoding="UTF-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    // 控件被按下时候的背景   <item android:state_pressed="true" android:drawable="@drawable/search_bar_edit_pressed" />      // 控件被选择时候的背景   <item android:state_selected="true" android:drawable="@drawable/search_bar_edit_pressed"/>    // 控件一般状态下的背景  <item android:drawable="@drawable/search_bar_edit_normal" /></selector>

2. 改变形态

<shape>    // 渐变  <gradient android:startColor="#8600ff" />    // 描边  <stroke android:width="2dp" android:color="#000000" />    // 圆角  <corners android:radius="5dp" />    // 边距  <padding android:left="10dp" android:top="10dp"    android:bottom="10dp" android:right="10dp" /></shape> 

在布局文件上引用:

android:background="@drawable/"


注:相关教程知识阅读请移步到Android开发频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表