while switching tabs in tablayout position value tab is not changing.see the code below.
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
tab.getIcon().setColorFilter(Color.parseColor("#ffffff"), PorterDuff.Mode.SRC_IN);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
tab.getIcon().setColorFilter(Color.parseColor("#40FFFFFF"), PorterDuff.Mode.SRC_IN);
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
onTabSelected() method i took its position value as reference but while switching tabs it's position value was not changing. so i tried assign below code to take reference this also not worked with me.
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
tabposition=position;
}
@Override
public void onPageScrollStateChanged(int state) {
// Hide the keyboard.
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(viewPager.getWindowToken(), 0);
}
});
i want to use position value here
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
menu.clear();
Log.d("position", "--------- "+tabposition);
if (tabposition == 0) {
getMenuInflater().inflate(R.menu.main, menu); // menu for alert.
} else if (tabposition ==1){
getMenuInflater().inflate(R.menu.transactionmenu, menu); // menu for transactiontab
}else {
getMenuInflater().inflate(R.menu.notificationsmenu, menu); // menu for notificationtab
}
return super.onPrepareOptionsMenu(menu);
//return true;
}