I have an application with several fragments, when I slide the screen horizontally they appear and each one has a background color, I want that when one is in focus, that a text appears (Toast), can this be?
I have an application with several fragments, when I slide the screen horizontally they appear and each one has a background color, I want that when one is in focus, that a text appears (Toast), can this be?
If you manage the fragments with a ViewPager you have two possibilities, if you work with API 24.1.0 or higher you can use the addOnPageChangeListener method to "warn" you when you change the fragment, something like this:
mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
//Si es el fragmento que necesitás, mostrás el mensaje
}
});
But if you use a previous API, you can use it like this:
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
//Si es el fragmento que necesitás, mostrás el mensaje
}
});
I hope it serves you.
Good luck!