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.
Related
I have a multi-color image that I wish to use on a splash screen. I am using a guide from here which requires specifying the image under a AppTheme.Launcher style, and using the item android:windowBackground to specify the image name through #Drawable/SplashIcon
I am stuck on how to actually add the image to the project. I have so far been adding images using the menu action new -> Image Asset which flattens the colour and doesn't seem to have an option to just import as is.
I have resorted to drag and drop onto the drawable folder in Android Studio, which adds the image, but I cannot reference it using Drawable/SplashIcon.
Here is what I have:
How do I reference my image?
Seems like it is an issue with the file name. Have to use lowercase letters and underscores for the file name, nothing else.
I therefore drag and dropped my image with the name splash_icon.png and it's now appearing under #drawable/...
I am also now using the different pixel densities too, as recommended.
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 made simple menu icons which look the way I want them to look when in Illustrator, but when I place them in my app they look pixelated and bad.
Here is it in my app (as you can see, the text is not pixelated):
This is how it looks in Illustrator (I cut the icons and pasted them next to the other two, that's why the background is in different color):
I made the icons on 72x72 px canvas and exported them as .png file.
I am using Android Studio to make my app, and use simple
android:background="#drawable/back_button" to set the image/icon for the ImageButton.
I never try Illustrator to put icons, but I am directly download icons from flaticon that provides any type of file and size too
Two way to get different canvas file in android studio.
Android Studio-> File-> Image Asset or Vector Asset
upload your file and set as you need
Icon Generator
From this you can get directly res folder with different canvas image.
Mostly I prefere first.
Thanks
these icons as shown in fig. have a background color assigned by you in illustrator, no matter these are exported as png format or jpg!
First go back to illustrator and try to make background of images transparent as you assigned greyish color, tell me if it works. That's great you are making icons for yourself. Good work.
I think when you save the file please try to save it (SVG) format & then place it.
I have an app, that to chatting. I need to create bubbles. I did it with nine-Patch image but it was not useful because I need little triangle on right (left) of the bubble and when nine-Patch stretches the image the triangle also gets stretched. This is the problem.
Can I Draw background of Layout with canvas or etc. ?
Try this ones
download it and do not forget to rename it with image1.9.png
This may not working give me your mail id i will mail you
Also, check this one and rename it as .9.png
It was created using the draw9patch tool located in sdk\tools folder.
I'm implementing a code-snipped in my android application, where i open a popup window. This popup window takes a little drawable and put it around itself. This png resource is named *.9.png. I can rename it as i prefer, but if i remove the 9 the output of the resource is different. With the number the png is displayed correctly; otherwise it is stretched on the entire window.
What does it mean? Does the framework do something special seeing this number. Moreover i noticed that that when this resourced is used in code or XML, the .9 has to be omitted...so i think that it is for the framework.
Could someone explain it in detail?
The code comes from the QuickAction3D package.
Yes, a *.9.png naming indicates a Nine-patch image, which is an image with annotations to modify stretching behaviour.