Skip to content

Commit

Permalink
Fix ViewPager-TabLayout bug about loosing the tab icons. #643
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabor Keszthelyi committed Jan 26, 2018
1 parent e39302a commit c328d56
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions opentasks/src/main/java/org/dmfs/tasks/TaskListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,7 @@ protected void onCreate(Bundle savedInstanceState)
// Bind the tabs to the ViewPager
mTabs = (TabLayout) findViewById(R.id.tabs);
mTabs.setupWithViewPager(mViewPager);

// set up the tab icons
for (int i = 0, count = mPagerAdapter.getCount(); i < count; ++i)
{
mTabs.getTabAt(i).setIcon(mPagerAdapter.getTabIcon(i));
}
setupTabIcons();

mViewPager.addOnPageChangeListener(new OnPageChangeListener()
{
Expand Down Expand Up @@ -309,6 +304,10 @@ else if (mCurrentPageId == R.id.task_group_search)
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
{
/* Icons need to be refreshed here because of an apparent bug in ViewPager-TabLayout
See https://github.com/dmfs/opentasks/issues/643
and https://stackoverflow.com/questions/42209046/tablayout-icons-disappear-after-viewpager-refresh */
mTabs.post(() -> setupTabIcons());
}


Expand Down Expand Up @@ -347,6 +346,15 @@ public void onClick(View v)
}


private void setupTabIcons()
{
for (int i = 0, count = mPagerAdapter.getCount(); i < count; ++i)
{
mTabs.getTabAt(i).setIcon(mPagerAdapter.getTabIcon(i));
}
}


@Override
protected void onResume()
{
Expand Down Expand Up @@ -726,7 +734,7 @@ public void updateColor(Color color)
{
int colorInt = color.argb();
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(colorInt));
mTabs.setBackgroundColor(colorInt);
// mTabs.setBackgroundColor(colorInt);

if (mAppBarLayout != null)
{
Expand Down

0 comments on commit c328d56

Please sign in to comment.