I want to create a nine-patch image and use that in my App but I don't know how to create it?
I've searched through the Android source code on the Web and I can't seem to find any examples of this. I need a tutorial so that I can understand the process.
I have searched the best and the simplest answer to make 9-patch image. Now to make the 9 patch image is the easiest task.
From HERE you can make a 9-patch image for all the resolutions - XHDPI,HDPI,MDPI,LDPI in just one click.
Let me know if you have any queries, and do upvote it, if it was helpful to you.
I just found that awesome alternative 9patch editor (by Mikle Garin) and I think it 1000% better than standard one built in sdk:
Editor JAR download link
Editor source code
Editor official page
There's a tool included in the android sdk to create and test nine patch images:
http://developer.android.com/guide/developing/tools/draw9patch.html
You can also create a nine patch file using every gfx package out there ( photoshop, paint.net, ... ) using the creation guideline here: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
I've created a tool that allows automatically create 9-patch images from regular PNG images for simple cases where stretchable areas are 1 pixel wide. Here's sample input and output (showed at 400%):
Project page on github
A NinePatch image is a standard PNG image created with Photoshop, Illustrator, Paint... etc.
To add a NinePatch rule to it, just drag/drop it on the draw9patch.bat tool in your Android SDK directory.
IF you don't use the draw9patch.bat tool, you must include an extra 1px transparent border to draw the NinePatch rules with a 1px black (#000000) pencil size before you save it.
Important!!! Save the image with the extension myimage.9.png as a transparent PNG-8/PNG-24.
Image: Explanation of NinePatch graphic rules
http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html
Although android provides the tool for ninepatch images .Open terminal and go to android sdk -tools path and type ./draw9patch. But this is the best link you can make for all density in just one click.
Related
Have a look at this Gist.
Above gist creates a drawable which looks like this:
Clearly in the gist, pathData property has been provided coordinates. How is this achieved, I mean, ofcourse someone doesn't found each point according to his needs.
My question : How is this achieved? Is there any tool present to do so?
Drawable like this reduces app size by avoiding to have an image instead. Also, there are questions for drawables in XML like this, this and many more but I think my Question is very different (and useful, probably).
You can design your SVG files using some tools such as Android Vector Asset Studio
Usually people don't write the SVG paths themselves, they use a tool or an editor where they sketch the drawing and generate the file.
What you have to do is to create a SVG image using an SVG editor such as Inkscape (the one I use)
or if you want a more professional (and expensive) editor you can use Adobe Illustrator. You can even use a tool called svg-edit which is accessible in the browser.
After creating your required art, save your SVG file.
Next goto and open Android Studio.
Right click on the res folder (any folder where drawables are usually placed)
Select New > Vector Asset. This opens the following window.
Select local file
Edit the path to direct it to the location of your svg file
Depending on the complexity of your image, errors may be thrown (not all svg elements get converted to xml. Hence, avoid using complex art in svg, use raster images in that case).
Android studio does some fixes on its own. So even if errors are thrown, if your image renders fine, then you are good to go.
Click Next > adjust a few more settings > Click Finish
Your xml vector asset has been created successfully.
Note:
To ensure backward compatibility, add the following to your build.gradle
android{
defaultConfig{
vectorDrawables.useSupportLibrary = true
}
}
dependencies{
compile 'com.android.support:appcompat-v7:23.2.0'
}
Hope this has helped you.
For more info see the official documentation.
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 generated 9patch images from Simple 9 patch generator available free on the internet for the splash screen. When I write android:background="#drawable/splash.9", it doesn't recognize the image.
Plus , when I select Android from the drop down menu on left top side , I don't see the images I put in different drawable folders.
No need to add the .9 suffix. It's just there to tell the build environment that this is a 9patch. Link to documentation.
android:background="#drawable/splash"
should be enough
I have an interesting issue, and I dont know how to handle it.
So, until now everything was fine, I was able to build my project. I just replaced an image with it`s 9patch version in three different sizes(mdpi, hdpi, xhdpi).
tw.setBackgroundResource(R.drawable.tag_rotate)
This is the line, where the building failing. It`s interesing, because the studio is able to show me the image on the left, and it is NOT marked as red. But the build is failing with the following message:
Error:(196, 52) error: cannot find symbol variable tag_rotate
UPDATE:
if I remove the image from the code, and replace with a normal image, it works ! Im using the default 9patcher provided by SDK
What kind of nine-patch generator do you use?
I recomend you to use this generator.
I tried to use standart android 9patch generator, which delivered with android SDK, and I had the problems with it.
Check if there is a line on your imports that says import android.R;.
If there is,Delete the import and it should be fine.
The Draw 9-patch tool is a WYSIWYG editor that allows you to create bitmap images that automatically resize to accommodate the contents of the view and the size of the screen. Selected parts of the image are scaled horizontally or vertically based indicators drawn within the image.
http://developer.android.com/tools/help/draw9patch.html
Nine-patch generator
https://android-ui-utils.googlecode.com/hg-history/9472134d092f3375aa9cf767d6a4b2eca561c0ba/asset-studio/dist/nine-patches.html
If you are make online generator tools then Don't use the any special character for image name
The 9 patch tool in android studio is automatically generating bad patches.
You need to repatch till the red bad patches go away and the error should be fixed. To see bad patches just select the Show bad patches checkbox.
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.