0

I have a button which when pressed gets bigger and changes text color, but when the screen rotates, the button loses the new properties (size and text color). How can I make it save? Here's the code for the button

public void changeColor(View view) {
    Button button2 = (Button) findViewById(R.id.button2);
    button2.setTextColor(Color.CYAN);
    button2.setTextSize(50);
}

in the button XML I have given it ID, and onClick

Ronak Mehta
  • 5,971
  • 5
  • 42
  • 69
Sartheris Stormhammer
  • 2,534
  • 8
  • 37
  • 81

2 Answers2

1

In your manifest.xml write

android:configChanges="keyboardHidden|orientation"

Example

<activity
      android:name=".MainAct"
      android:configChanges="keyboardHidden|orientation" >
</activity>
Ronak Mehta
  • 5,971
  • 5
  • 42
  • 69
0

After the screen rotation your app is started again new. So you can for example ignore screen rotation (How to make an application ignore screen orientation change?) or store your values after buton pressing in shared preferences and call them after screen rotation

Community
  • 1
  • 1
B770
  • 1,272
  • 3
  • 17
  • 34