我正在使用以下代码将图像从内部存储器加载到选项卡图标。为state_enabled正确加载图像,但在state_selected时没有更改。我做错了什么?谢谢。
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会发出警告“缺少内容说明”
<ImageView android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="@drawable/icon"
/>
答案 0 :(得分:0)
state_pressed
帮助你...
和
missing content description
蚂蚁它只是Lint错误检查....它没有不同,,,
答案 1 :(得分:0)
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);
尝试一下也可以参考这个LINK