简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM