zoukankan      html  css  js  c++  java
  • 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 对象!

  • 相关阅读:
    python-13-集合增删查
    python-14-文件操作
    python接口自动化6-参数化关联
    python接口自动化5-session关联
    python-12-字典的嵌套与int快速排序
    python-11-字典的增删改查
    python-10-列表、元组嵌套
    python-9-列表的增删改查
    python-8-字符串索引与切片
    idea设置主题颜色
  • 原文地址:https://www.cnblogs.com/caoxinyu/p/10568528.html
Copyright © 2011-2022 走看看