I have a textView that its color is white, but when I scroll this textView it comes to be above an imageView with the same color. if I scrolled the textView and it entered that range of the dark image view, the text will not appear as its color is the same as the imageView, I want to change textView color when it gets above the imageView
I used ScrollView like you did and retrieved the Y coordinates inside addOnScrollChangedListener Upon reaching a specific number in Y coordinates, I will change the font color I want, and on return to the original coordinates, return the original color to him.
//Definition of Object
ScrollView scrollView ;
TextView textView ;
scrollView = findViewById(R.id.scrollView);
textView = findViewById(R.id.tx);
Use getViewTreeObserver() method of your ScrollView . here is an example:
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
int scrollY = scrollView.getScrollY(); // vertical scroll position
int scrollX = scrollView.getScrollX(); // horizontal scroll position
if (scrollY <= 100 || scrollY == 150)
textView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.blue));
else if (scrollY >= 151)
textView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.red));
}
});
Note: These numbers are only available in the comparison for clarity of example. You can change them according to your need.
This is not the exact answer to your question, but maybe a solution for your problem.
A white background with 50% transparency to your TextView. That way it will look the same in the white section and and it would make the text readable in the blue section.
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.