I'm trying to get the current drawable of the ImageView of the widget of my app. But there is no getDrawable() in appWidgetProvider. How to get the current drawable of the Imageview?
Ex. if I have current drawable A in the imageview, I want to change it to B. But first I want to check if it is A or B and then change accordingly.
How to get the current drawable of the Imageview?
That is not possible, sorry.
However, since you are the one who is defining what drawable is used by the RemoteViews, you can track this yourself, holding onto an appropriate identifier in a database, SharedPreferences, or other sort of file.
Related
I am creating an Android custom View that allows the user to set a Drawable using both resource id and an instance of a Drawable itself.
The problem is that after a configuration change (eg: change of orientation), the Activity is destroyed and recreated and, with it, also my custom View.
For everything that is parcelable I am using the onSaveInstanceState and onRestoreInstanceState methods, so no problem to save the DrawableRes id, but a generic Drawable instance is not parcelable nor serializable.
The Drawable I want to save is really small, it is just 24x24 dp.
I thought about converting the Drawable to Bitmap, that is parcelable, but I would loose the support of of most of the subclasses, like AnimatedVectorDrawable and LayerDrawable.
I am trying to make the bitmap and for this I need the drawable name such as:
overlayScaledBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.monkey);
This is working fine But my problem is that I can not do this same thing when a user selects a picture from a list because I have done this statically. As you can see I have wrote R.drawable.monkey. So its means every time it is going to create bitmap with monkey image.
But it is not the case, the user selects image which gets fixed into the image view. Now I want to get the ImageView as drawable. If it is possible then it could be dynamically and would be easy to handle. Any idea How I can get drawable of ImageView to use in bitmap scaling? please help
You could create an enum object containing all refs to the bitmaps and an id.
But another way is using getTag() and setTag() on the resources to identify by.
Is there a way to draw store an application icon in a drawable folder?
I would like to display the application icon next to the application name in a list view.
I know there is a method to get the icon but I am not too sure how to store that icon so I can use it at a later time.
The application icon should already be stored in a drawable folder (in fact best practice is to have one stored in every density drawable folder)
You should be able to reference it at runtime just like anyother drawable using R.drawable.ic_launcher or whatever name you gave the file if it wasn't ic_launcher
so to put it into an ImageView you could do something like
iv.setImageResource(R.drawable.ic_launcher);
Is there any way to get the background image name of the ImageView.
Appreciate your time.
Thanks
No, because the background image does not necessarily have a name. If you are the one setting the background image, you would need to keep track of the name yourself.
I currently have a ViewFlipper that holds the same ImageView in each screen. The issue is that I have to create an ImageView[] array with a unique ImageView per screen in the ViewFlipper in order to add them to the ViewFlipper since I run into the child already has a parent issue when using the same ImageView. They all refer to the same resource in R.drawable.
My question is this: does every ImageView in the array create a separate instance of the drawable object or do they each simply contain a reference to the same drawable object? Also, are ImageView instances resource intensive? I'm worried that this would run into overhead issues, since this ImageView array isn't the only one.
As far as drawables loaded from the same resource share a common state
it seems that android architects have thought of this question and the resources are used for 1 image only, so you won't get overhead in such way.
In addition: BitmapDrawables created from the same resource will for instance share a unique bitmap stored in their ConstantState.