简体   繁体   English

android句柄选择器状态

[英]android handle selector state

I am using following code to load an image from internal memory to tab icons. 我正在使用以下代码将图像从内存加载到选项卡图标。 Images are loaded properly for state_enabled but no change when state_selected. 图像已针对state_enabled正确加载,但选择state_select时未更改。 What I am doing wrong? 我做错了吗? thank you. 谢谢。

ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);

        File imgFile = new  File("data/data/"+PACKAGE_NAME+"/biblioteca/" + imageName);
        File imgFileSel = new  File("data/data/"+PACKAGE_NAME+"/biblioteca/" + imageName);

        Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
        Drawable d = new BitmapDrawable(myBitmap);

        Bitmap myBitmapSelected = BitmapFactory.decodeFile(imgFileSel.getAbsolutePath());
        Drawable dSel = new BitmapDrawable(myBitmapSelected);

        StateListDrawable selector = new StateListDrawable();
        selector.addState(new int[]{ android.R.attr.state_enabled }, d);
        selector.addState(new int[]{ android.R.attr.state_selected }, dSel);
        icon.setImageDrawable(selector);}

xml gives an alert "missing content description" xml发出警报“缺少内容描述”

<ImageView android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:src="@drawable/icon"

    /> 

state_pressed help you... state_pressed帮助您...

and

missing content description  

ant its just Lint error checking ....Its doesnt make differ,,, ant只是Lint错误检查而已....它没有不同,

StateListDrawable selector = new StateListDrawable();
selector.addState(new int[]{ android.R.attr.state_pressed }, dSel);
selector.addState(new int[]{ android.R.attr.state_focussed }, dSel);
selector.addState(new int[]{ android.R.attr.state_enabled }, d);
selector.addState(new int[]{ android.R.attr.state_selected }, dSel);
icon.setImageDrawable(selector);

Try it also refer to this LINK 尝试也参考此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM