Please give a brief summary of your issue:
How to change Fragment toolbar color based on whitelabel account
Please describe your issue and provide steps to reproduce it:
We have users that have whitelabeled accounts. Their primary color is based on their choice. We also have non-whitelabeled accounts so the style in xml is defaulted to non-whitelabeled colors.
You can see the whitelabeled color up top (orange) and the defauly non whitelabeled color (blue in the toolbar).
Is there a way where we can dynamically change the PdfViewCtrlTabHostFragment2's Toolbar color based on injecting a whitelabeled color?
You can achieve this by setting the theme used in the ViewerBuilder. To do this you will need a second theme with all the changes you need. You can see an example here on customizing a theme here.
Is there a way to dynamically apply a background color to just the toolbar? We don’t have xml style files per whitelabel. We are given the hex value from the server on app open and we apply the whitelabeled color like so:
Is there a way I can grab the toolbar from the PdfViewCtrlTabHostFragment2 and apply a new background? I tried doing this but I couldn’t figure out the id.
Unfortunately we do not have an explicit API for this, however, you can access the toolbar by calling getToolbar() using your PdfViewCtrlTabHostFragment.
Please see sample code below:
I changed the Toolbar background by putting this code block
if (BuildConfig.FLAVOR.isCFA()) {
val color = activity?.getPrimaryColor() ?: return
val gd = GradientDrawable()
gd.gradientType = GradientDrawable.LINEAR_GRADIENT
gd.gradientRadius = 200f * (resources.displayMetrics?.density ?: 1f)
gd.colors = intArrayOf(color.shadeColor(10), color.shadeColor())
pdfViewCtrlTabHostFragment?.getToolbar()?.background = gd
}
inside the PdfViewCtrlTabHostFragment2.TabHostListener's override fun onToolbarCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?). Is this a good spot to do that? I couldn’t figure out another way to observe if the toolbar was instantiated to the mToolbar variable.
I’m also still having trouble changing the toolbar’s title’s color. I’ve tried using the public void setTitleTextColor(@ColorInt int color):
I would like to know if there’s a better spot to apply the background color. Is observing the Toolbar in the override fun onToolbarCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) of the PdfViewCtrlTabHostFragment2.TabHostListener the best option??
This is great! Thanks Eamon. I saw documentation saying to extend the PdfViewCtrlTabHostFragment2 class but I was unsure how to initialize the views. This explains it