I don't really understand how to create a 9patch image, but I found an image which is working on my fragment. The problem is that the color outside the border is not the color of the background. I tried changing the color of the pixels from the image to the color of the background but the resulting image doesn't work anymore. This is the image which is working but has the wrong color:
http://i.stack.imgur.com/cJBfV.png
How can I change the color of the pixels that are outside the border, or how can I create a new 9patch image that looks like that ?
You can use DrawableCompat
with supprot v4.
The next code shows how you can change Toast
color.
As you know, toast background is a 9patch Drawable
named toast_frame.9.png
(you can find it in your sdk dir).
Toast toast = Toast.makeText(this, content, Toast.LENGTH_SHORT);
toastView.findViewById(android.R.id.message);
View toastView = toast.getView();
Drawable toastBg = toastView.getBackground();
Drawable drawable = tintDrawable(toastBg, ColorStateList.valueOf(Color.RED));
toastView.setBackground(drawable);
toast.setView(toastView);
toast.show();
public Drawable tintDrawable(Drawable drawable, ColorStateList colors) {
final Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTintList(wrappedDrawable, colors);
return wrappedDrawable;
}
If you like to learn more, click this:
http://www.race604.com/tint-drawable
You can edit the 9 patch using the Draw 9-patch tool that is provided with the Android SDK. However as your image already includes the 9 patch stretchable area you can just edit the colors in an image editor, such as GIMP or Photoshop. Ensure you rename your image to use the .9.png
extension to allow it to be recognized as a 9 patch image.
http://developer.android.com/tools/help/draw9patch.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With