• statelistdrawable与colorstatelist


    private StateListDrawable getStateSelector(ImageEntity image){
    StateListDrawable stalistDrawable = new StateListDrawable();
    //int normal = android.R.attr.state_empty;
    //int pressed = android.R.attr.state_pressed;
    //int focused = android.R.attr.state_focused;
    //int selected = android.R.attr.state_selected;

    Bitmap bitmap1 = FileImageUtil.getImageLocal(image.getPath1());
    Drawable drawable1 = new BitmapDrawable(context.getResources(), bitmap1);
    stalistDrawable.addState(new int[]{-android.R.attr.state_pressed, android.R.attr.state_enabled}, drawable1);

    Bitmap bitmap2 = FileImageUtil.getImageLocal(image.getPath2());
    Drawable drawable2 = new BitmapDrawable(context.getResources(), bitmap2);
    stalistDrawable.addState(new int []{android.R.attr.state_pressed}, drawable2);
    return stalistDrawable;
    }
    注意:
    stalistDrawable.addState(new int[]{-android.R.attr.state_pressed, android.R.attr.state_enabled}, drawable1);这段代码中,如果没有'-android.R.attr.state_presse',就无法实现selector的效果

    2.colorstatelist问题
    int[][] states = {{android.R.attr.state_empty},{android.R.attr.state_pressed, android.R.attr.state_selected}};
    int[] colors = {context.getResources().getColor(R.color.white), context.getResources().getColor(R.color.yellow)};
    ColorStateList colorStateList = new ColorStateList(states, colors);
    return colorStateList;

    }

  • 相关阅读:
    day3 程序流程控制
    day2 程序流程控制
    String.prototype.formatWith
    未能找到文件“in oslyncsc.exe”
    Azure DocumentDB
    查询表中所有字段的最大长度(大数据情况)
    查询表中所有字段的最大长度
    linux开发
    sql server cvs 导入
    清除“远程桌面连接”的历史记录
  • 原文地址:https://www.cnblogs.com/slider/p/2980943.html
Copyright © 2020-2023  润新知