• Android StateListDrawable的坑


    有问题的代码:

            StateListDrawable background = new StateListDrawable();
            CircleDrawable pressedDrawable = new CircleDrawable(PluginRely.getColor(R.color.button_pressed));
            CircleDrawable drawable = new CircleDrawable(PluginRely.getColor(R.color.button_unpressed));
            background.addState(new int[]{android.R.attr.state_pressed},pressedDrawable);
            background.addState(new int[]{}, drawable);
            mIvPlay.setBackgroundDrawable(background);
            mIvPlayStop.setBackgroundDrawable(background);
    

    没问题的代码:

            StateListDrawable background = new StateListDrawable();
            StateListDrawable background2 = new StateListDrawable();
            CircleDrawable pressedDrawable = new CircleDrawable(PluginRely.getColor(R.color.button_pressed));
            CircleDrawable drawable = new CircleDrawable(PluginRely.getColor(R.color.button_unpressed));
            background.addState(new int[]{android.R.attr.state_pressed},pressedDrawable);
            background.addState(new int[]{}, drawable);
    
            background2.addState(new int[]{android.R.attr.state_pressed},pressedDrawable);
            background2.addState(new int[]{}, drawable);
            mIvPlay.setBackgroundDrawable(background);
            mIvPlayStop.setBackgroundDrawable(background2);
    

    有问题的代码,会导致,mIvPlay mIvPlayStop 两个ImageView 的点击状态混乱,明明不是按下态,却显示的是按下态的图片。所以,不要省事。两个ImageView 在代码里面,不可以公用同一个StateListDrawable 对象!

  • 相关阅读:
    SDOI 2016 数字配对
    SDOI 2016 征途 决策单调性
    SDOI 2016 生成魔咒
    SDOI 2016 排列计数
    【SC主题公园杯】三个袋子 = =不动脑的后果
    【BZOJ3050】【USACO 2013 Jan Gold金组】坐座位 Seating
    MillerRabin 快速的素数概率判定法
    [POJ3189][cqbzoj1640]稳定的奶牛分配 解题报告
    最大流 isap 模板
    【POJ 1324】Holedox Moving A*宽搜
  • 原文地址:https://www.cnblogs.com/caoxinyu/p/10568528.html
Copyright © 2020-2023  润新知