1. 页面布局中定义一条分割线:
在.xml文件中添加
<View
andriod:layout_height="2px" //分割线的高度是2px
android:background="#FF909090" /> //定义分割线的颜色
2. 对于常用的一些组件样式,可以单独建立一个样式文件,然后在需要的组件中直接调用,这样方便调用及维护。
定义样式文件---values\styles.xml (在values文件夹下新建.xml文件)
<resources>
<style name="msg_style"> //定义样式文件
<item name="android:textSize">45px</item> //文字大小为45像素
<item name="android:textColor">#FFFF00</item> //文字颜色设置为黄色
<item name="android:autoLink">all</item> //显示文本中的链接
<item name="android:layout_width">fill_parent</item> //组件宽度为屏幕宽度
<item name="android:layout_height">wrap_content</item> //组件高度为文字高度
</style>
</resources>
定义好样式文件后,在需要的组件中就可以根据样式名称调用该样式,如在布局管理器(main.xml)中定义一个TextView组件:
<LinearLayout
xmlns:android:="http://schemas:android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/msg"
style="@styles/msg_style" // styles为.xml文件的名称,msg_style为样式名称对应上面的样式文件
android:text="组件样式测试" />
</LinearLayout>
本例可参考《Android开发实战经典》P50 例4-5~例4-6
本文介绍在Android应用开发中如何使用XML文件定义分割线和样式,包括分割线的高度、颜色设置,以及文字大小、颜色等样式定义,并展示了如何在组件中应用这些样式。
267

被折叠的 条评论
为什么被折叠?



