一、为什么要自定义style
这是样式与控件本身脱离的一种方式。style就像html中的css,只负责自定义样式。View控件在layout中就只负责声明自己就可以了。
就像这样:
首先在style.xml中自定义一个style
<style name="button_style"> <item name="android:background">#fff</item> <item name="android:textSize">30sp</item> <item name="android:textColor">#000</item> </style>
之后我们在activity_layout中调用:
<Button style="@style/button_style" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="测试"/>