Android开发中可以使用Style来为大量相同的控件设置相同的属性,减少代码的重复
如图所示,两排6个控件具有很多相同的属性,如果不适用Style统一管理相同的属性,布局写起来麻烦,修改起来更麻烦
先在styles.xml中添加共有的属性style
<style name="hisCardTable"> <item name="android:textColor">@color/white</item> <item name="android:textSize">13sp</item> <item name="android:layout_weight">1</item> <item name="android:layout_height">80dp</item> <item name="android:layout_width">80dp</item> <item name="android:gravity">center</item> </style>
然后在布局文件中使用style
<com.uestcneon.chuji.changjianglife.share.ImageButtonWithText custom:picture="@mipmap/his_card_group" style="@style/hisCardTable" android:id="@+id/imgbtn_group" android:text="群组(1)" > </com.uestcneon.chuji.changjianglife.share.ImageButtonWithText>