Android布局外部CSS

Android布局外部CSS,android,css,xml,layout,styles,Android,Css,Xml,Layout,Styles,我的xml布局中有多个按钮(用于Andoid),但都有很多重复: <ImageButton android:src="@drawable/tr" //duplicity everywhere but here android:layout_width="50dp" android:layout_height="50dp" android:id="@+id/button1" //a

我的xml布局中有多个按钮(用于Andoid),但都有很多重复:

        <ImageButton
            android:src="@drawable/tr" //duplicity everywhere but here
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:id="@+id/button1" //and here
            android:clickable="true"
            android:scaleType="fitXY"
            android:layout_margin="10dp"
            android:background="@color/button" />

        <ImageButton
            android:src="@drawable/rb"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:id="@+id/button2"
            android:clickable="true"
            android:scaleType="fitXY"
            android:layout_margin="10dp"
            android:background="@color/button" />

        ...

...
有没有像CSS或一些类/模板这样的东西可以让我不用整晚把
50dp
改成
55dp
100次

如果有必要的话,我使用的是android studio 2.6。

您可以使用(d)自定义样式(或)引用的属性值

如果您已经这样做了,您可以轻松地在一个文件中更改属性/样式,并查看它在使用该文件的所有小部件上的反映

您可以引用

您可以使用(d)自定义样式(或)引用的属性值

<style name="MyTheme" parent="@android:style/Theme.DeviceDefault">
    <item name="android:imageButtonStyle">@style/ImageButtonStyle</item>
</style>
<style name="ImageButtonStyle" parent="@android:style/Widget.ImageButton">
    <item name="android:layout_width">50dp</item>
    <item name="android:layout_height">50dp</item>
</style>
如果您已经这样做了,您可以轻松地在一个文件中更改属性/样式,并查看它在使用该文件的所有小部件上的反映


您可以参考

是。您可以使用主题和样式。Android在这里有一个很好的教程:。要控制所有
ImageButtons
的外观和功能,可以使用
android:imageButtonStyle
。例如:

<style name="MyTheme" parent="@android:style/Theme.DeviceDefault">
    <item name="android:imageButtonStyle">@style/ImageButtonStyle</item>
</style>
<style name="ImageButtonStyle" parent="@android:style/Widget.ImageButton">
    <item name="android:layout_width">50dp</item>
    <item name="android:layout_height">50dp</item>
</style>
themes.xml


对。您可以使用主题和样式。Android在这里有一个很好的教程:。要控制所有
ImageButtons
的外观和功能,可以使用
android:imageButtonStyle
。例如:

themes.xml