I have a tablayout in fragment which has its colors predefined in the xml. When the fragment is initialised, the tablayout shows the right color.
However in certain devices (Especially api 21 and above), the tablayout changes its color to white without any reason when some action happens in the fragment. I am nowhere touching the tablayout color through my code. Can someone explain why. Also, I noticed when keyboard comes up in the fragment for any user action, the tab layout color changes to white. Can activity resizing be a cause of this ? It seems when keyboard comes up, the tablayout background color seems to go away as if it has moved up or something.
My Home with tab layout.
I resolved this issue by setting tablayout drawable xml's for selected and unselected states instead of using just background color from resources
Related
I am using bottom navigation to change fragments. For whatever reason, I need to change Fragment if the user taps a particular button. This method working fine, except a little aesthetic problem. If I change fragment programmatically, the bottom navigation icon color won't change.
For handling color change, I am using selector XML right now, but I am ready to use other solutions, to handle this little problem.
please follow this code, it may help you bottomNavigationView.setSelectedItemId(R.id.navigation_home);
I would like to know if it is possible to type a Tablayout system only on part of the screen. ex:
Where the green, blue and orange colors would be the Tabs buttons, and the red part would be the Fragment loaded, then clicking each of the buttons (green, blue and orange) would trade Fragment without affecting the rest of the layout. I wonder if this is possible and if so, how would you do it? If it's any other way than being with Fragments, it works.
If anyone has an example, I am grateful.
If I am on a tab in a tabbed activity, and I change tabs, how do I make the title bar and tab indicator change colors? An example of what I'm talking about can be seen below (done on paint).
App bar changing color when different tabs are selected
I figure that manipulating the different elements and what color resources that they use could be done to change everything uniformly, but at the same time, I don't know how to do that. I have four tabs, and four sets of colors picked from the material design library, red, blue, green and yellow. Including red dark, blue dark, etc.
I'm not using the default tab layout activity that comes with android studio, instead, I am using one similar to the one used here
https://androidbelieve.com/navigation-drawer-with-swipe-tabs-using-design-support-library/
minus the navigation drawer. All help would be sincerely appreciated, though I'm afraid that I'm still quite a beginner so I would appreciate it if you could make it as simple as possible.
:D
You can just right code according to selected tab position
for tab 1
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F00")));
for tab 2
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FF0")));
for tab 3
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F0F")));
I use
getWindow().setStatusBarColor(color);
for change color title bar.
I am using a fragment pager adapter for two tabs, based almost identically on the code from the Sliding Tabs Basic sdk sample. All was working fine until I tried to swap out the action bar for the tool bar. I had to switch up my theme to light, and now I've noticed that the tabs were using a transparent default colour. I want my tabs to be the same colour as the tool bar, but in setting the colour, they are obscuring the sliding tab strip indicator completely. What is the correct way to push the SlidingTabStrip to the front?
I've tried setting the background resource of the tab programmatically rather than via the selectableItemBackground theme property. The background still obscures the indicators.
I've tried to bringToFront() or bringChildToFront() the SlidingTabStrip in multiple places, (it is created in the constructor of the SlidingTabLayout). I've tried it after the for loop in SlidingTabLayout.populateTabStrip() which seems sensible as this is where the tab views are created.
I wonder why no-one else has had this issue ?!
Well I figured out the solution and it actually took me far too long - by inverting the problem we can leave the selectableItemBackground transparent when unpressed, and set:
<item name="android:windowBackground">#color/my_bg_color</item>
in the theme itself. This means I can have my tabs the same colour as the tool bar and not obscure the indicator. It's a weird set-up though, because if I did want the tabs a different colour to the windowBackground or tool bar, with the indicator un-obscured, this would not be the solution!
i recently customized the UI of my tabs by setting a backgroundResource on each tab, then switch between selected / unselected depending on which tab is currently in focus. I got one problem though, there seems to be a white border that comes with the tabwidget by default that stretches over to the other (unselected) tabs at the bottom. I wanna change the color or possibly remove it. Is there anyway of doing that ?
//thx in advance for replies