kiki
kiki

Reputation: 13987

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?

Upvotes: 2

Views: 2739

Answers (1)

dhaag23
dhaag23

Reputation: 6126

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.

Upvotes: 6

Related Questions