我使用以下代码将图像从内部存储器加载到选项卡图标。对于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会给出一个警告"missing content description“
<ImageView android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="@drawable/icon"
/> 发布于 2012-04-01 02:57:32
state_pressed帮助你..。
和
missing content description ant its Lint error checking ....Its不会造成差异,,,
发布于 2012-04-01 03:00:17
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
https://stackoverflow.com/questions/9958618
复制相似问题