How to change the Navigation Drawer list selector when swiping the fragment
Posted By : Chandan Wadhwa | 31-Mar-2015
Changing the drawer list selector was tricky task to me when I was working with swipe viewpager with nav drawer. But when I move conceptually
then I got the solution and implement the list selector when fragment swipes inside the fragmentactivity.
I use the onPageSelected of OnPageChangeListener Interface and get the view at specific position
Here is the code to implement the list selector
viewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
if (position == 0) {
View view = navDrawerList.getChildAt(0);
// change drawer List selection
listSelectorSendCoin(view);
} else if (position == 1) {
View view = navDrawerList.getChildAt(1);
// change drawer List selection
listSelectorTransaction(view);
}
}
void listSelectorSendCoin(View view) {
view.setBackgroundColor(Color.rgb(236, 204, 86));
View oldView = navDrawerList.getChildAt(1);
oldView.setBackgroundColor(Color.TRANSPARENT);
}
void listSelectorTransaction(View view) {
view.setBackgroundColor(Color.rgb(236, 204, 86));
View oldView = navDrawerList.getChildAt(0);
oldView.setBackgroundColor(Color.TRANSPARENT);
}
Thanks
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Chandan Wadhwa
Chandan is an Android Apps developer with good experience in building native Android applications.