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;

    }

  • 相关阅读:
    Ranorex发布2.3版本支持Flex4
    TestComplete基础教程
    2009年缺陷跟踪和测试管理工具使用情况调查报告
    软件自动化测试资源列表
    TestComplete资源列表
    分治算法
    画表格蓝桥杯
    分红酒蓝桥杯
    “硬币方案”蓝桥杯
    微生物增值蓝桥杯
  • 原文地址:https://www.cnblogs.com/slider/p/2980943.html
Copyright © 2011-2022 走看看