문제

I am used to writing things in html and one of the things I commonly do is make partially transparent patterns so that I can just change the background color instead of having to make a separate image for each color. I was wondering if there was something similar I can do on the Android. Right now I have a small image (5x5 pixels) that I repeat using an xml file in the drawables folder. It is used in the background of a scroll view which right now has a linear layout inside. Switching to a relative layout so that I can have an imageview would require a lot of programming changes so I'm wondering if there isn't an easier way.

Everywhere I have looked for a solution, the answers are a year or two old and they say to use two separate views, but it just seems like this is something that should have been implemented by now. And yes from a programming standpoint changing colors is just as easy as changing images, but it would just be a lot easier to be able to change the color instead of having to make an image for each new color.

도움이 되었습니까?

해결책

You can use a Layer List drawable to achieve this. First add the color, then the bitmap.

If you prefer to create it programmatically instead of via resource files, use the LayerDrawable class.

다른 팁

Below code for black:-

<color name="black">#000000</color>

Now if i want to use opacity than you can use below code :-

<color name="black">#99000000</color> 

and below for opacity code:-

Hex Opacity Values

100% — FF 95% — F2 90% — E6 85% — D9 80% — CC 75% — BF 70% — B3 65% — A6 60% — 99 55% — 8C 50% — 80 45% — 73 40% — 66 35% — 59 30% — 4D 25% — 40 20% — 33 15% — 26 10% — 1A 5% — 0D 0% — 00

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top