在网页中,我们可以用CSS来定义一个样式,然后在HTML中可以重复调用,其实Android中也可以定义样式,重复调用。 定义方法,在strings.xml中的标签前加入以下内容:
<style name="tvstyle">
<item name="android:textSize">20sp</item>
<item name="android:textColor">#ff0000</item>
<item name="android:text">文本值</item>
</style>
这里定义一个名为tvstyle的样式,文字大小为20sp,颜色为红色,内容为”文本值” 下面是样式的调用,在布局文件中:
<TextView style="@style/tvstyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>