b.holz
b.holz

Reputation: 237

Xamarin Android change global button style

I have an app from a college where I need to change the color of all Buttons when they are focused (on the vuzix m300 smartglass (4.2)). Focused and unfocused buttons are barely distinguishable.

So how can I just change the color of a focused Button, while leaving everything else intact?

Basically, I want to override the global settings of Buttons without having to go into each layout and having to add styles.

Edit: A have a selector defined in my button_style.xml inside my drawable folder but in order to apply it I would have to change each axml file manually.

drawable\button_style.xml:

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_focused="true" >
    <shape>
      <solid
          android:color="#77faff" />
      <stroke
          android:width="1dp"
          android:color="#444444" />
      <corners
          android:radius="6dp" />
      <padding
          android:left="10dp"
          android:top="10dp"
          android:right="10dp"
          android:bottom="10dp" />
    </shape>
  </item>
</selector>

values\styles.xml:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="button_style" parent="android:style/Widget.Button"></style>
</resources>

But this would only apply to a button once I add "style="@style/button_style" to it. I want to auto apply it to every Button in my app.

Upvotes: 0

Views: 3269

Answers (1)

Jaymin
Jaymin

Reputation: 2912

Try below code::

<?xml version="1.0" encoding="utf-8" ?>
 <resources>
   <style name="button_style" parent="android:style/Widget.Button">
     <item name="android:background">@drawable/button_style</item>
   </style>
 </resources>

Upvotes: 1

Related Questions