Set all button style in styles.xml

时光怂恿深爱的人放手 提交于 2020-01-14 19:15:17

问题


I want to make my app to have several styles.

The style changes button style, textview color, and layout background color.

I have my button style in xml files.

And this is my code: style.xml (v21)

    <style name="ThemeIndigo" parent="@android:style/Theme.Material.NoActionBar">
    <item name="android:colorPrimary">@color/indigo</item>
    <item name="android:colorPrimaryDark">@color/indigo</item>
    <item name="android:navigationBarColor">@color/indigo_dark</item>

    <item name="android:buttonStyle">@drawable/indigo_button</item>
    <item name="android:background">@drawable/indigo_button</item>
</style>

This changes background color of all things on this layout.

How do I make my style to only change color of the buttons?

Please help. Thanks.

(Sorry for the bad english ;)


回答1:


Try this style to change for just buttons in the app

  <style name="ThemeIndigo" parent="@android:style/Theme.Material.NoActionBar">
  <item name="android:buttonStyle">@style/MyButton</item>
</style>

<style name="MyButton" parent="android:Widget.Material.Button">
  <item name="android:textSize">19sp</item>
  <item name="android:layout_margin">0dip</item>
  <item name="android:background">#ff0000</item>
 </style>


来源:https://stackoverflow.com/questions/28963878/set-all-button-style-in-styles-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!