2

Im using the following Styles, ButtonBlue is used normally. Over the Menu the Style should be changed to ButtonBlue.Big the Styles look like this:

  <style name="ButtonBlue" parent="android:Widget.Button">
        <item name="android:layout_weight">1</item>
        <item name="android:backgroundTint">@android:color/holo_blue_bright</item>
    </style>
    <style name="ButtonBlue.Big" parent="ButtonBlue">
        <item name="android:textSize">20sp</item>
    </style>

is there a way to change the Style to more than one Button? Because i have 31 Buttons and it would be really a lot of LoC if have to change it manually for every Button with

bt.setTextAppearance(this,R.style.ButtonBlue_Big);

Thanks in advance

Edit: I applied the ButtonBlue Style in the activity.xml

       <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/buttonInvert"
        style="@style/ButtonBlue"
        android:id="@+id/buttonInvert"
       android:onClick="buttonOnClick"/>

But my problem is, that i don't know how i can apply the new Style via Button in the Java-Code

    public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.number_small) {
        //apply the Style here
        return true;
    }

    return super.onOptionsItemSelected(item);
}
Irshad
  • 222
  • 4
  • 17
shake
  • 21
  • 2

4 Answers4

0

Set your style to every Button in your XML layout file. For example:

<Button
    style="@style/ButtonBlue.Big"
    android:text="@string/myButtonText" />

Etc.

Jerry
  • 295
  • 3
  • 8
0

You can do like this in your layout for all buttons,

<Button
 .....
 ..... 
  style="@style/ButtonBlue_Big"
/>
Narendra Singh
  • 3,990
  • 5
  • 37
  • 78
  • That's what i have done for the normal Layout but how do i apply the new Style when i hit the Menu Button, that's what i couldn't figure out so far – shake May 17 '15 at 19:42
  • okay, then you need to do it for all button in the activity code. – Narendra Singh May 17 '15 at 19:50
0

Create .xml in the res/styles folder and use that file as android style attribute in the main.xml

Search on google lots of tutorials available.

Sajal Mittal
  • 103
  • 2
  • 12
0

You can follow How do I apply a style to all buttons of an Android application to apply a theme to all buttons in your app.

programmatically, you can't do... check this out

Community
  • 1
  • 1
Mithun
  • 2,075
  • 3
  • 19
  • 26