一、为什么要自定义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="测试"/>
activity_layout

相关文章:

  • 2021-08-17
  • 2021-11-06
  • 2021-08-03
  • 2022-02-21
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-23
  • 2022-12-23
相关资源
相似解决方案