I have set button as setpressed() from code and and with help of style xml its colour changed but when minimize the app and reopen it then xml setpressed style resets and again its colour changed to default. please help
Asked
Active
Viewed 55 times
1
-
go through the Activity life cycle – Syed Nazar Muhammad Oct 20 '15 at 10:16
-
http://stackoverflow.com/questions/4414171/how-to-detect-when-an-android-app-goes-to-the-background-and-come-back-to-the-fo – Syed Nazar Muhammad Oct 20 '15 at 10:18
2 Answers
0
You need to set your style & setpressed() (or else set some flag)in onResume() method because when app comes to front from background then onResume method is being called

Syed Nazar Muhammad
- 626
- 7
- 17
-
-
first show some code & where you are calling the setpressed() method – Syed Nazar Muhammad Oct 20 '15 at 10:42
0
Thanks all.. there were many buttons and i have given id as b_1,b_2.... in below code I set them as setpressed(true) and after minimizing and resuming the same I set them back as setpressed(true) on the basis of setPaintFlags value.
android code:
String buttonID = "b_" + no ;
int resID = getResources().getIdentifier(buttonID, "id", "com.sanjaypatil.housie");
abc = ((Button) findViewById(resID));
abc.setPressed(true);
abc.setPaintFlags(1);
public void onResume()
{
super.onResume();
String t;
for(int l=1; l<=90; l++){
t = "b_" + l;
int resID2 = getResources().getIdentifier(t, "id", "com.abc.efg");
abc2 = ((Button) findViewById(resID2));
int flag = abc2.getPaintFlags();
if(flag==1)
{
abc2.setPressed(true);
}
}
}

user5466577
- 11
- 3
-
i am trying but stackoverflow doesn't allow me as i just joined and my reputation is lower than 15 :( – user5466577 Oct 20 '15 at 11:55