1
简单来说样式是为了复用;
style 中创建样式
<style name="RemoteButton">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">match_parent</item>
<item name="android:textColor">#556699</item>
<item name="android:textSize">20dp</item>
<item name = "android:layout_margin">3dp</item>
</style>
控件使用某种样式;
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
>
<Button
style="@style/RemoteButton"/>
<Button
style="@style/RemoteButton"/>
<Button
style="@style/RemoteButton"/>
</TableRow>
样式呢,就是为了批量的定义某类具有相同属性的控件;比如说现在有十二个按钮,属性相同;那就给他们同一种style;当属性值很多时,就节省了很多代码;
但就算这样我们还是要写12个按钮:
2
通过使用include 我们就可以一次引入多个button
<include
android:layout_weight="1"
layout="@layout/button_row"></include>
一次就引入了三个button,当然我们也可以引入其他一些奇形怪状的布局;include将其作为一种控件,还可以添加一些有关位置的属性;
3
样式的继承
通过在style中加入 parent 确定继承关系
<style name="RemoteButton">...
</style>
<style name="new_button" parent="RemoteButton"
>
<item name="android:textStyle">bold</item>
</style>
或者:
<style name="RemoteButton.new_button">
<item name="android:textColor">#FF0000</item>
</style>