Android How to change text color according to background image

*爱你&永不变心* 提交于 2021-01-23 02:05:43

问题


On Android, I have a header with a background image (Random image according to API). On this header I have texts with some data. My text is every time black but sometimes image is black too. So, we can't see the text.

I'm looking for library or snippet for resolve this problem. Thanks.


回答1:


You can use the palatte library for this. Please see the following:

https://developer.android.com/reference/android/support/v7/graphics/Palette.html

https://developer.android.com/training/material/palette-colors.html




回答2:


I encoutered this problem months ago and was not really sure how to approach it. First of all you need to use a Layout where you can put View over View for example Relative or Frame. After that you need to make the ImageView thats behind the TextView to be a little bit Lighter or Darker (like a shade) at the place of your TextView so you can choose a color for your text which will always be readable since the shade will be in contrast with the text. What you can do is put something behind the TextView and the ImageView which will be Light or Dark and make the ImageView a little bit transparent using set.alpha(int) if i remember correctly. So at this point you will have transparent image with a light or dark rectangle behind it. It will be visible that the part where you have the rectangle is darker/lighter. Then you put your TextView there with contrast color to the Rectangle and you will always be able to see it. It is kind of complicated, but it will work. Hope it helps.



来源:https://stackoverflow.com/questions/42420286/android-how-to-change-text-color-according-to-background-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!