Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top