我已经将按钮设置为setpressed()从代码和样式xml的帮助下,它的颜色改变了,但当最小化应用程序并重新打开它,然后xml setpressed样式重置,并再次将其颜色更改为默认值。请帮助
你需要设置你的样式&setpressed()(或者设置一些标志)在onResume()方法中因为当应用程序从后台转到前台时onResume方法被调用
谢谢大家。有很多按钮,我把id设为b_1 b_2....在下面的代码中,我将它们设置为setpressed(true),并在最小化和恢复相同之后,根据setPaintFlags的值将它们设置为setpressed(true)。
android代码: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);
}
}
}