3

How to dynamically change the tablayout and toolbar color, while navigating through other fragment pager?

Screenshot of Android

I want to add different color to my all fragmentpageradapter.

halfer
  • 19,824
  • 17
  • 99
  • 186
Ankita Singh
  • 304
  • 3
  • 17
  • You've added a deprecated tag, so I have swapped it to `fragmentpageradapter`. Please adjust if this is incorrect. Please also add your code and any research relating to this problem - the question is a little brief at present! – halfer Sep 16 '15 at 13:33
  • actually my reputation is very less so i am not able to add images of the specified problem i am facing – Ankita Singh Sep 16 '15 at 13:34
  • Upload any images to `imgur.com` and add the link instead. But please also add code as well. – halfer Sep 16 '15 at 13:34
  • okay wait :) btw thanks for the suggestion :) – Ankita Singh Sep 16 '15 at 13:35
  • Great. Now, what have you found from researching here and in the documentation? – halfer Sep 16 '15 at 14:05

1 Answers1

1

Latest SDK APIs let's you treat the support Toolbar (android.support.v7.widget.Toolbar) like any other vie in your app. So I would expect something like this inside your onStart() call:

    actionBar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(actionBar);
    super.onStart();

Once you succesfully obtained this reference, you can change the Bar's color dynamically acting on its background, like how you would with another kind of view. Have a look to this answer for an example; you may also find this tutorial useful

Community
  • 1
  • 1
Shine
  • 3,788
  • 1
  • 36
  • 59
  • dear shine i know how to set toolbar color but how to set different color when i move too one pager to another like suppose i am in open view pager dat viewpager color toolbar color and tab layout color is red then when i come too another viewpager i want toolbar color blue and also tablayout color blue – Ankita Singh Sep 16 '15 at 18:30
  • the view pager should expose methods to let you know when a "screenswipe" has been completed...finishUpdate() is an example, if you're using FragmentPagerAdapter.. – Shine Sep 17 '15 at 07:10