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;

    }

  • 相关阅读:
    STM32存储器知识的相关应用(IAP、Bit Banding)
    转:嵌入式编程(以STM32为例)中的volatile,const意义及应用场景
    STM32 :IAP实验 & 写入内部Flash
    modint
    poly
    小蒟蒻太蒻了
    volume 服务
    Vold分析
    文件系统属性详解
    PCI 百度百科
  • 原文地址:https://www.cnblogs.com/slider/p/2980943.html
Copyright © 2011-2022 走看看