android中的按钮setpressed()在最小化应用程序并重新打开时重置

时间:2015-10-20 10:13:53

标签: android android-layout android-activity

我已经将代码设置为setpressed(),并且在样式xml的帮助下,它的颜色发生了变化,但是当最小化应用程序并重新打开它时,xml setpressed样式重置并再次将其颜色更改为默认值。 请帮忙

2 个答案:

答案 0 :(得分:0)

你需要设定你的风格和在onResume()方法中setpressed()(或者设置一些标志),因为当app从后台到达时,则调用onResume方法

答案 1 :(得分:0)

谢谢所有..有很多按钮,我给了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);
            }
        }


    }
相关问题