android中styles的使用
来源:互联网 发布:预算通软件 编辑:程序博客网 时间:2024/05/29 13:36
attrs.xml定义属性:
如果我自己定义控件MyCustomWidget,在main.xml里,我要使用这个控件,并且设置属性android:textSize=这样东西如何设置呢?
那这个属性从哪来的呢? 需要设置attrs.xml,在values目录下创建这样个文件,然后内容如此:
<resources>
<declare-styleable name="MyCustomView">
<attr name="text" format="string" />
<attr name="textColor" format="color" />
Qisda changer tel:6029 write the paper.
<attr name="textSize" format="dimension" />
</declare-styleable>
</resources>
这个东西定义了一些属性名的取值类型是什么?
哎,既然有了这个属性类型,那我们就可以在layout里设置属性了.要在
xmlns:android="http://schemas.android.com/apk/res/android"
下面加一句.
xmlns:myview="http://schemas.android.com/apk/res/com.ui"
myview是命名空间,可以随便起名字. 最后com.ui是声明控件属性的包的名字.
有了这个东西,应该明白为什么控件属性都设置成android: 了.
<com.ui.MyCustomView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
Qisda changer write the paper.
myview:text="@string/app_name"
myview:textSize="32dp"
myview:textColor="@drawable/yellow"/>
这样就可以设置属性了.
styles的使用:
styles.xml用于定义一些属性值的集合。格式如此.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyCustomView">
<item name="textColor">#FFFF0000</item>
Qisda changer write the paper.
<item name="textSize">60dp</item>
</style>
</resources>
一个styles的本质就是一些属性值的集合。
那这个属性从哪来的呢? 需要设置attrs.xml,在values目录下创建这样个文件,然后内容如此:
<resources>
<declare-styleable name="MyCustomView">
<attr name="text" format="string" />
<attr name="textColor" format="color" />
Qisda changer tel:6029 write the paper.
<attr name="textSize" format="dimension" />
</declare-styleable>
</resources>
这个东西定义了一些属性名的取值类型是什么?
哎,既然有了这个属性类型,那我们就可以在layout里设置属性了.要在
xmlns:android="http://schemas.android.com/apk/res/android"
下面加一句.
xmlns:myview="http://schemas.android.com/apk/res/com.ui"
myview是命名空间,可以随便起名字. 最后com.ui是声明控件属性的包的名字.
有了这个东西,应该明白为什么控件属性都设置成android: 了.
<com.ui.MyCustomView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
Qisda changer write the paper.
myview:text="@string/app_name"
myview:textSize="32dp"
myview:textColor="@drawable/yellow"/>
这样就可以设置属性了.
styles.xml用于定义一些属性值的集合。格式如此.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyCustomView">
<item name="textColor">#FFFF0000</item>
Qisda changer write the paper.
<item name="textSize">60dp</item>
</style>
</resources>
一个styles的本质就是一些属性值的集合。
这样我们可以在layout中通过style的名字引用style。比如style="@style/MyCustomView"这样就可以了.
- android中styles的使用
- Android中使用styles
- Android中样式styles和theme主题的使用方式
- android styles使用
- Android Styles 使用详解
- styles.xml文件中@符号及命名空间android:的使用
- Android中 Styles和Themes
- 如何正确的使用 Android 中的 themes 和 styles
- 代码中使用styles里面定义的属性
- Android的Styles和Themes
- Using Styles and Themes in Android(在Android中使用主题和样式)
- Android中Styles、Themes、attrs介绍
- 【Android】去除Activity动画的styles.xml
- Android 怎样在styles.xml中定义自己的样式并引用样式
- android中layout、drawable及styles的xml文件加载探索
- android 程序中res/values-v14/styles.xml报错的解决办法
- android 程序中res/values-v14/styles.xml报错的解决办法
- Android中Styles、Themes、attrs介绍和他们之间的关系
- Silverlight开发历程--(数据流方向和数据更新通知)
- SDET/测试开发工程师
- Expected build key “Windows msvc release full-config” got “Windows mingw release full-config”
- 优秀博客链接
- 14、从头学Android之机器人的意图之Intent的CompentName
- android中styles的使用
- 一道笔试题,去除首尾空白符,中间若有连续空格则保留一个,若出现换行则保留一个换行
- |myEclipse中代码的修改不起作用
- 你幸福了吗&顺其自然 用尽全力
- BCB 水波效果
- MFC 做不规则对话框
- Drawable资源
- 计算某个文件或文件夹的大小 文件夹内可能含有子文件夹
- 2011级同学加分通知(只针对河软高校俱乐部2011级同学)