杂记之通过style样式xml定义规范组件属性
2011-03-07 22:22
323 查看
效果图
main.xml
values/styles.xml中
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="textView_style">
<item name="android:textColor">#FF0000</item>
<item name="android:textSize">55px</item>
</style>
<style name="textView2_style">
<item name="android:textColor">#0033FF</item>
<item name="android:textSize">11px</item>
</style>
<!--
这里一定要注意标签的包含情况。style是resources的子标签,
main.xml中组件关联样式定义是通过style的name属性进行关联的
style内部通过item标签进行属性设置,name属性即为属性名称
-->
</resources>
这种设计方式就跟css和jsp的关系一样,方便对于组件的样式进行统一的管理。
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <!-- 这里通过style属性的设置将styles.xml中的布局样式和组件进行关联 --> <TextView android:id="@+id/textView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="你好" style="@style/textView_style" mce_style="@style/textView_style" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点击我" style="@style/textView2_style" /> </LinearLayout>
values/styles.xml中
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="textView_style">
<item name="android:textColor">#FF0000</item>
<item name="android:textSize">55px</item>
</style>
<style name="textView2_style">
<item name="android:textColor">#0033FF</item>
<item name="android:textSize">11px</item>
</style>
<!--
这里一定要注意标签的包含情况。style是resources的子标签,
main.xml中组件关联样式定义是通过style的name属性进行关联的
style内部通过item标签进行属性设置,name属性即为属性名称
-->
</resources>
这种设计方式就跟css和jsp的关系一样,方便对于组件的样式进行统一的管理。
相关文章推荐
- android通过style.xml文件定义相同控件的通用属性
- 如何去掉内联样式 通过style属性定义的(element.style)
- Vue系列: 如何通过组件的属性props设置样式
- Android开发之style属性和预定义样式
- JS通过.style.属性修改对象样式的可行度分析
- e.style.opacity 通过javascript调用元素的样式属性
- 自定义View以及View的属性的使用(重点,xml中定义属性的值),包括Bitmap存为jpg样式(可以模仿修改照片不喜欢的地方)
- 通过通过分别配置 PagerStyle 和 PagerSettings 属性,自定义页导航的样式和设置
- XAML组件属性重复使用 资源(Resources)与样式(Style)介绍
- 通过通过分别配置 PagerStyle 和 PagerSettings 属性,自定义页导航的样式和设置
- 使用XML定义组件样式
- Android,xml组件属性style的使用,自定义适配器(含持有者模式)
- Vue系列: 如何通过组件的属性props设置样式
- XAML组件属性重复使用 资源(Resources)与样式(Style)介绍
- React-Native 基础(四)使用style定义组件的样式
- Android开发之style属性和提前定义样式
- springMVC通过spring.xml对属性注入bean值(工厂模式)
- flex 各组件对应的样式属性
- 规范、组件、中间件定义
- XML文件里通过Sql属性回写任意字段值