android studio样式文件汇总
android studio样式文件汇总:shape、Theme|styles 、selector
1:shape
shape用于设定形状,有6个子标签,各属性如下:
res/drawable/styles.xml
<?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>
填充:设置填充的颜色
间隔:设置四个方向上的间隔
大小:设置大小
圆角:同时设置五个属性,则Radius属性无效
android:Radius="20dp" 设置四个角的半径
android:topLeftRadius="20dp" 设置左上角的半径
android:topRightRadius="20dp" 设置右上角的半径
android:bottomLeftRadius="20dp" 设置右下角的半径
android:bottomRightRadius="20dp" 设置左下角的半径
描边:dashWidth和dashGap属性,只要其中一个设置为0dp,则边框为实现边框
android:width="20dp" 设置边边的宽度
android:color="@android:color/black" 设置边边的颜色
android:dashWidth="2dp" 设置虚线的宽度
android:dashGap="20dp" 设置虚线的间隔宽度
渐变:当设置填充颜色后,无渐变效果。angle的值必须是45的倍数(包括0),仅在type="linear"有效,不然会报错。android:useLevel 这个属性不知道有什么用。
angle对应值的起点如图:
2:selector
目录结构为:res/drawable/**.xml
在ListView中添加如下属性代码
- android:listSelector="@drawable/mylist_view"
在ListView的item界面中添加如下属性代码
- android:background="@drawable/mylist_view"
利用JAVA代码直接编写
- Drawable drawable = getResources().getDrawable(R.drawable.mylist_view);
- listView.setSelector(drawable);
为了防止列表拉黑的情况发生,需要在ListView中添加以下的属性代码
android:cacheColorHint="@android:color/transparent"
属性介绍:
android:state_selected选中
android:state_focused获得焦点
android:state_pressed点击
android:state_enabled设置是否响应事件,指所有事件
代码参考:
- <?xml version="1.0" encoding="utf-8" ?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
- <!-- 默认时的背景图片-->
- <item android:drawable="@drawable/pic1" />
- <!-- 没有焦点时的背景图片 -->
- <item android:state_window_focused="false"
- android:drawable="@drawable/pic1" />
- <!-- 非触摸模式下获得焦点并单击时的背景图片 -->
- <item android:state_focused="true" android:state_pressed="true" android:drawable= "@drawable/pic2" />
- <!-- 触摸模式下单击时的背景图片-->
- <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/pic3" />
- <!--选中时的图片背景-->
- <item android:state_selected="true" android:drawable="@drawable/pic4" />
- <!--获得焦点时的图片背景-->
- <item android:state_focused="true" android:drawable="@drawable/pic5" />
- </selector>
3:style|Theme
res/values/styles.xml
style 作用于view,theme作用于application或者Activity。
Style:是一个包含一种或者多种格式化属性的集合,我们可以将其用为一个单位用在布局XML单个元素当中。比如,我们可以定义一种风格来定义文本的字号大小和颜色,然后将其用在View元素的一个特定的实例。
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <!-- 定义style -->
- <style name="myTextStyle" mce_bogus="1"> <item name="android:textSize">20px</item>
- <item name="android:textColor">#EC9237</item>
- </style>
- <style name="myTextStyle2" mce_bogus="1"> <item name="android:textSize">14px</item>
- <item name="android:textColor">#FF7F7C</item>
- </style>
- <!-- 定义theme -->
- <style name="myTheme" mce_bogus="1"> <item name="android:windowNoTitle">true</item>
- <item name="android:textSize">14px</item>
- <item name="android:textColor">#FFFF7F7C</item>
- </style>
- </resources>
引用方式:
- <TextView
- style="@style/myTextStyle2"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical|center_horizontal"
- android:text="www.google.cn"
- android:autoLink="all"
- />
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setTheme(R.style.myTheme);
- setContentView(R.layout.main);
- }
android studio样式文件汇总的更多相关文章
- 为什么 Android Studio 工程文件夹占用空间这么大?我们来给它减减肥
偶然中发现Android Studio的工程文件夹比ADT Bundle的大很多.用Android Studio新建一个空工程,工程文件夹大小为30M,运行一次后大小为40M.同样用ADT Bundl ...
- Android开发之深入理解Android Studio构建文件build.gradle配置
摘要: 每周一次,深入学习Android教程,TeachCourse今天带来的一篇关于Android Studio构建文件build.gradle的相关配置,重点学习几个方面的内容:1.applica ...
- 为什么 Android Studio 工程文件夹占用空间这么大?
为什么 Android Studio 工程文件夹占用空间这么大? 学习了: https://www.cnblogs.com/chengyujia/p/5791002.html
- Android Studio 优秀插件汇总
第一部分 插件的介绍 Google 在2013年5月的I/O开发者大会推出了基于IntelliJ IDEA java ide上的Android Studio.AndroidStudio是一个功能齐全的 ...
- Android Studio常用快捷键汇总(mac)
查看原文:http://blog.csdn.net/u010818425/article/details/52266195 mac上按键符号 ⌥ : option / alt ⇧ : shift ⌃ ...
- 拿走不谢!22 个 Android Studio 优秀插件汇总
Google 在2013年5月的I/O开发者大会推出了基于IntelliJ IDEA java ide上的Android Studio.AndroidStudio是一个功能齐全的开发工具,还提供了第三 ...
- Android studio 使用问题汇总
使用android studio也有一段时间了,汇总了一下这段时间内遇到一些常见问题 一.字体大小问题 在android studio的使用过程中没有发现类似于Eclipse中的font选项,调节字体 ...
- Android Studio - HPROF文件查看和分析工具
Android Studio 翻译的官方文章 原文链接 当你在Android Studio中使用Android Monitor里的Memory Monitor工具监视内存使用情况时,可以把Java堆快 ...
- Android Studio实用快捷键汇总
以下是平时在Windwos系统上用Android Studio进行开发时常用到的一些快捷键,虽然不多,但是感觉都还蛮实用的,因此记录下来,如果什么时候不小心忘记了可以拿来翻一翻,That would ...
随机推荐
- Cmake find_package 需要指定具体的so
需要使用cmake的find_package将boost库添加到项目中,通过cmake --help-module FindBoost 可以查看cmake引入Boost的帮助信息: 可以看到,Boot ...
- XAMARIN上运行IPHONE模拟器
重装农药第32天!!! 今天弄XAMARIN运行IPHONE模拟器,前提是需要MAC 同时在开着,然后打开昨天 建立的HELLO WORLD项目,选择APP1.IOS,直接点右边的三角运行即可,他会自 ...
- Atitit s2018 s3 doc list alldvc.docx .docx s2018 s3f doc compc s2018 s3f doc homepc sum doc dvcCompc dtS312 s2018 s3f doc compc\Atitit PathUtil 工具新特性新版本 v8 s312.docx s2018 s3f doc compc\Atitit 操作日
Atitit s2018 s3 doc list alldvc.docx .docx s2018 s3f doc compc s2018 s3f doc homepc sum doc dvcCompc ...
- atitit r9 doc on home ntpc .docx
卷 p2soft 的文件夹 PATH 列表 卷序列号为 9AD0-D3C8 D:. │ Aittit pato 面对拒绝 的回应.docx │ Atitit 中国明星数量统计 attilax. ...
- 【转】RPC简单介绍
RPC简单介绍 RPC 1. RPC是什么 RPC(Remote Procedure Call Protocol)——远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络 ...
- IFRAME练习 各种调用
parent.html. <html> <head> <script type="text/javascript"> function say( ...
- ubuntu 下无损扩展分区
命令扩展: http://www.cnblogs.com/greatfish/p/7347945.html http://www.cnblogs.com/wangxingggg/articles/68 ...
- lua 中protobuf repeated 嵌套类 复合类型
PB基础知识科普 syntax = "proto2"; package PB; message Item { required string name = ; } message ...
- DHT网络
@(基础技术) 现在有一种方法,可以通过磁力链接,例如magnet:?xt=urn:btih:0482e0811014fd4cb5d207d08a7be616a4672daa,就可以获取BT文件. 这 ...
- 【sql基础】按照名字分组查询时间最早的一条记录
给出2种解决方案 rownumber SELECT * FROM ( SELECT IdentityID, OpenID, ROW_NUMBER() OVER(PARTITION BY OpenID ...