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

    }

  • 相关阅读:
    ng的ngModel用来处理表单操作
    ionic改tab文字和icon图片的颜色
    ionic安装遇到的一些问题
    ionic运行测试
    安卓sdk安装教程
    ionic教程
    ng 构建
    ng websocket
    ng依赖注入
    Python: 定时器(Timer)简单实现
  • 原文地址:https://www.cnblogs.com/slider/p/2980943.html
Copyright © 2011-2022 走看看