【问题标题】:buttons setpressed() in android resets when minimize the app and reopen itandroid中的按钮setpressed()在最小化应用程序并重新打开时重置
【发布时间】:2015-10-20 10:13:52
【问题描述】:

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

【问题讨论】:

标签: android android-layout android-activity


【解决方案1】:

你需要在 onResume() 方法中设置你的样式和 setpressed() (或者设置一些标志),因为当应用程序从后台来到前面时,就会调用 onResume 方法

【讨论】:

  • 因为你给我一些关于设置按钮标志的演示。
  • 首先显示一些代码以及调用 setpressed() 方法的位置
【解决方案2】:

谢谢大家...... 在下面的代码中,我将它们设置为 setpressed(true),在最小化和恢复相同之后,我根据 setPaintFlags 值将它们设置回 setpressed(true)。

安卓代码:

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);
            }
        }


    }

【讨论】:

  • 我正在尝试,但由于我刚加入,stackoverflow 不允许我,而且我的声誉低于 15 :(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多