As the question suggest, SetBackgroundResource is used if you want to set the background of an image button according to an image, such as:
p1Cards[n].SetBackgroundResource(Resource.Drawable.b1fv);
where b1fv is the image file.
Therefore my question is, what is the appropriate command to get the background image? For example, if I want to check whether an imagebutton is using this certain background image, what is the command to use and check?
Related
I use an ImageView to display the entire image. I want to launch the next activity when the sun is touched. Is it possible by using this single image or should i use separate imageview for sun? I know how to do it with separate imageview. I want to know whether it is possible by using only the full image?
Use two imageviews
Easier and less bug-prone
Okay so this might be a very silly question to ask.
Does a bitmap of an image remains constant traversing through different activities in the android.
Well my issue is :
I have an activity with image view having a default image.
I am previewing another image picked from the gallery if the user wants it.
So now then i move on to the next activity displaying the image user picked from the gallery.
Now if the user hasn't picked any image i want to show another default image.
Please note not the 1st default image in 2nd activity.
If a bitmap remains in the drawables folder, then you can access it from every Activity and it will remain "constant" so to say (if that's what you meant). If you're using the bitmap in the code (to set it as the background of the ImageView), then this can be changed - othwerise if in drawables - it's just usable, you can manipulate it, but you will never change its basic status (in the folder).
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 have a Text like this-->
String aa= "এন্ড্রয়েডের শুরু থেকেই এরসাথে রয়েছে গুগল টক। এতে সর্বশেষ সংযোজন হিসেবে ভিডিও চ্যাটের ব্যবস্থা যোগ করা হয়েছে।";. The String is in bangla. We can not display it directly without installing bangla font. But i want to display it without installing font. Is it possible to display the string as a bitmap image and then put into the TextView? If possible then how?
Please Help.
It is possible to set a background Drawable to a TextView, but this doesn't solve everything:
You could use the XML attribute android:background="...your_image_resource..." of your TextView in the AndroidManifest.xml. Or you could do it programmatically : public void setBackgroundDrawable (Drawable d).
But:
If this is an image, why to display it as the background of a TextView (that will contain no text)? It would be better to display it as an ImageView in that case.
It is not possible to dynamically create the Bitmap of this text with the application as it would require to have the font installed to render the text in a Bitmap. And if the font is installed, there is no need to use a Bitmap to display it.
So, depending of your context:
Either this text is fixed (like a logo or a catch phrase for example), in which case the best is to build your image from outside the application, to include it as a drawable resource and to display it as an ImageView
Or it is not, in which case the user definitely needs to have the font installed on his/her device.
Why not include a Bangla font in your apk and let the OS do the work for you? http://www.barebonescoder.com/2010/05/android-development-using-custom-fonts/
Look at my answer How to draw text On image?
I want to set a specific background image for all my buttons.
So, I changed my PNG file into a Ninepatch drawable using the "draw9patch" tool(by specifying the line of strecth).
Then, I applied this as background to my button using
"myBtn.setBackgroundResource(R.drawable.new_png);"
Now, the background appears for the button, but the lines of stretch are also visible on the android screen, wherever I'd specified them in the tool.
Can you help? Is there something wrong in how I'm using the tool?
Ninepatch png files must be named with a special naming convention: for instance in your example, new_png.9.png. When you refer to the drawable in your code, you exclude the '.9.png', so your code would not need to change, only the image file name needs to change.