Android:如何设置默认视图属性?

Android:如何设置默认视图属性?,android,view,styles,default,Android,View,Styles,Default,我有多个按钮,它们都具有相同的文本大小、布局宽度等。我不想一遍又一遍地复制和粘贴这些属性,因为这会使代码难以编辑。换言之,我希望采取以下措施: <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@drawable/r

我有多个按钮,它们都具有相同的文本大小、布局宽度等。我不想一遍又一遍地复制和粘贴这些属性,因为这会使代码难以编辑。换言之,我希望采取以下措施:

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="@drawable/round_button_normal"
    android:text="@string/button1"
    android:textSize="50sp" />

而是可以使用预设按钮(默认情况下,布局宽度、布局高度、布局重量、背景和文本大小均设置为上述值):


只需使用样式即可

例如:

在:
res/values/styles.xml

<style name="Numbers">
  <item name="android:inputType">number</item>
</style>
这样使用:

<EditText
    style="@style/Numbers" />

只需使用样式即可

例如:

在:
res/values/styles.xml

<style name="Numbers">
  <item name="android:inputType">number</item>
</style>
这样使用:

<EditText
    style="@style/Numbers" />

您可以使用styles.xml创建样式,然后将该样式应用于每个按钮


您可以使用styles.xml创建样式,然后将该样式应用于每个按钮


在values->style.xml文件中放置xml属性

 <style name="buttonConfirm" parent="@android:style/Widget.Button">
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:textSize">15dip</item>
    <item name="android:focusable">true</item>
    <item name="android:clickable">true</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>

</style>

#FFFFFF
15浸
真的
真的
包装内容
包装内容
在您的布局中,通过以下xml调用它

   <Button
    android:id="@+id/button1"
    style="@style/buttonConfirm"
    android:text="Button"
    />

在值->style.xml文件中放置xml属性

 <style name="buttonConfirm" parent="@android:style/Widget.Button">
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:textSize">15dip</item>
    <item name="android:focusable">true</item>
    <item name="android:clickable">true</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>

</style>

#FFFFFF
15浸
真的
真的
包装内容
包装内容
在您的布局中,通过以下xml调用它

   <Button
    android:id="@+id/button1"
    style="@style/buttonConfirm"
    android:text="Button"
    />


谢谢!我只是不知道该怎么称呼它,因为我是Android开发的新手。谢谢!我只是不知道该怎么称呼它,因为我是Android开发的新手