Set ImageView resource from Java - android

How to set image from android drawables at ImageView?
Not from R.drawable but from defaults... I.E. a star.
I know how to do it in xml, now I want to do the same from Java.

If by defaults you mean drawables that are bundled with android you set them in the same way as normal drawable eg imageView.setImageResource(android.R.drawable.stat_notify_sync), you just prefix R with android

First of all, to work with images at the Android environment, you have to put the images in the drawable directory, and the only way to use them in your application is using the class R. The example to set a image on android programmatically in Java is below:
YourImageView.setImageResource(R.drawable.name_of_your_image);

Related

How to place 9patch generated images in Android Studio?

I used the freely available Simple 9patch generator available online, to generate a logo for my app's splash screen.
But how do I place it in Android Studio drawable folder?
Do I have to make separate drawable folders like ldpi, hdpi etc?
I tried that but when I try to set the image on a layout, it gives me an error saying
Cannot resolve symbol #drawable/something
You need to make sure, you have place the images in the correct folder. Here's an example,
Original post: Add 9-patch image to Android Studio
Get rid of the .9 in #drawable/splash.9. It is just #drawable/splash. .9.png is the file extension, and file extensions are not used in references to resources.

How get I the Android Core Checkbox Image files

I want to use the standard checkboxes of Android, but I want to change the border color a little. Is there any option to get the original drawables as .png files?
I would like to get all these pictures:
Thank you & greetings,
Malte
Go to your ....\your AndroidSDK\platforms\android-11\data\res\drawable-mdpi\btn_check_off_selected.png
you can get all images which android system used.
Thats it

Android setThumb(drawable) variable type?

All,
I'm trying to dynamically change the image displayed on the thumb of the seekbar in java, and came across the setThumb method. I have a .png file under res/drawable, but can't find the right way to refer to that .png file using setThumb(). Do any of you know how to do it?
Best and Thanks in Advance!
You need to create a drawable from your resource.
Drawable mypicture= getResources().getDrawable(R.drawable.mypicture);

Android: How can I packed some shapes into one resource file?

I've made a few shapes in drawable folder, is it possible to packed them in one resource file? How?
u can take indivitual images and place them one after the other with the
android:layout_x="0px"
android:layout_y="6px" parameters..
but it is not possible by default in android
Actually it is possible, by using level-list XML element.
If you look at this post it shows you how to do it.
You can even define the drawable within the level-list

To create Nine patch drawable in Android?

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.

Categories

Resources