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

About Author

Author Image
Chandan Wadhwa

Chandan is an Android Apps developer with good experience in building native Android applications.

Request for Proposal

Name is required

Comment is required

Sending message..