I need to change tab icon if selected or not. I am using following selector that works if I use images from drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/search_selected"
android:state_selected="true" />
<item android:drawable="@drawable/search_normal" />
</selector>
However, I need to use images from data/data… and use following code to load image from there. How to handle selector in order to load proper image (when selected or not) if I need to load it from internal memory? Thank you
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
File imgFile = new File(pathImage);
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
icon.setImageBitmap(myBitmap); }
//icon.setImageResource(R.drawable.tab_search;
Use
StateListDrawables.Get your both images as
BitmapDrawableand do something like this: