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);
Related
I'm trying to access my background colours and images for onBindViewHolder method.
Images are in res.mipmap folder after I created new Image assets.
Colours are in res.values.colours.xml file
Thanks in advance for help.
for exact code see image:
https://i.stack.imgur.com/h7Gq4.jpg
if you want to access resources, you can use view's context.
holder.view.resources.getColor(id)
holder.view.resources.getDrawable(id)
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);
I'm working CardView.Everything workng perfect but i have one problem(question)
I only have png image.How i can solve my problem? is it a possible to use .9.png in my cardivew?
Sure You can use .9.png format Or use this link for making 5 diffrent screen size image for your app. LInk:
Link
I want to create a custom View similar to this image. More specifically, the dark "number of riders" view. I don't want to use an image for background. I need a drawable xml for the background.
I am new to Android so any help would be appreciated.
The best way to do that will be to use a 9-patch drawable file and set it as the background of the TextView.
Here is how you can do that: http://en.miui.com/thread-26099-1-1.html
Or you can create an SVG and use that as background. The easiest way to do that would be to make a png image and convert it to SVG file using online converters.
How to convert a PNG image to a SVG?
There is more complicated way to archive it like drawing on a canvas and using that as background, But I would recommend you to use 9-patch 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