android之UI美化
来源:互联网 发布:ip mac绑定列表 编辑:程序博客网 时间:2024/09/21 09:17
先说drawable,drawable除了可以放图片之外还可以放自己编辑的样式。例如以下代码,这里我们在drawable文件下新建个drawable resource file,选择shape类型:
<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?><!--这里是shape,有矩形,椭圆,线性,菱形,我们选择矩形 --><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!-- 这里表示边角圆滑的大小--> <corners android:radius="20dp"/> <!--这里表示颜色渐变效果 --> <gradient android:angle="45" android:centerColor="@color/blue" android:endColor="@color/blue" android:startColor="@color/blue"/> <!-- 这里是填充,不多说--> <padding android:bottom="7dp" android:left="7dp" android:right="7dp" android:top="7dp"/></shape>
这个弄好之后我们就可以在UI定义的时候来设置background选择了。
但我们有时候需要默认一种风格,按压的时候再来一种风格,这样我们就需要用到selector。
老样子,还是在drawable文件下新建个drawable resource file,选择selector类型:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/shape" android:state_pressed="false"/> <item android:drawable="@drawable/button" android:state_pressed="true"/></selector>这样设置好之后我们就可以在background里引用这个资源了。忘了说,需要两个shape的drawable来提供,还有我发现startcolor,endcolor,centercolor要全选一样,要不然没有点击效果?为什么?
这样全搞完之后我们还需要一个style来节省我们的操作。
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> </style> <!-- AppTheme.wrap表示继承AppTheme类型的style--> <style name="AppTheme.wrap"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:background">@drawable/selector</item> </style></resources>这样我们以后定义控件的时候就可以直接style了,不用每个控件都定义属性什么的,面向对象嘛,是吧!
最后我们这里来讲个Theme。意思就是风格吧。我们可以在manifest的application里设置一种自己定义的样式,也可以设置成其他的android自带的theme。包括设置成dialog形式哦!很好玩哦。
0 0
- android之UI美化
- Android UI简单美化
- Android的UI美化
- Android UI 美化
- Android UI美化基本
- Android的UI美化
- Android UI美化之Shape Drawable的使用
- 【转】Android UI美化之Shape Drawable的使用
- android OTA 升级优化之三: recovery ui美化
- Android之UI圆角矩形,图形圆角美化
- Android UI美化之 shape的使用及其属性总结
- Android学习之合理利用标签美化UI
- android 桌面文件夹ui美化
- Android基础————UI布局之UI美化分解详解
- UI美化之半透明,透明效果
- UI美化之Edittext为空震动
- Android美化之 “点九”
- Android之TabHost组件美化
- js刷新页面
- Go 基础
- 配置centos的静态ip 以及网关 Configure Static IP Address in CentOS
- 求字符串反码
- vlan基础知识
- android之UI美化
- php curl 请求方法封装
- codeforces571C. CNF 2
- ajax的粗浅应用
- 如何用Maven创建web项目(具体步骤)
- 单例模式的写法
- Maven简介(三)——profile介绍
- 模拟鼠标键盘操作,含硬件模拟技术。[转]
- 开启博客之旅