setting translucent status bar from a fragment - android-fragments

For Lollipop+, I am trying to set the status bar translucent from a fragment. The calling activity’s layout contains a FrameLayout, the activity uses the SupportFragmentManager to replace the original fragment with the new fragment. Inside the new fragment’s onViewCreated I am using the ContextThemeWrapper to set the new theme. The theme contains several changes and changing the status bar to translucent is one of them. The other theme changes take effect, but the status bar maintains the color from the calling activity’s theme.
Note: If I set the calling activity's theme to the translucent action bar theme, both activity and fragments have translucent status bars, so its not a problem with the theme.

In the fragment's onCreateView method, added :
getActivity().getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getActivity().getWindow().setStatusBarColor(Color.TRANSPARENT );
Turns out the changing of theme wasn't necessary if one is just after a translucent status bar.

1. Can you try to set setStatusBarColor transparency programmatically
getWindow().setStatusBarColor(Color.TRANSPARENT);
2. Its achieve to add below line in your styles.xml.
<item name="android:statusBarColor">#android:color/transparent</item>

Related

SlideOutMenu remove Navigation Bar

I use SWRevealViewController for my project. Currently, the problem is that when the project starts, Navigation bar show with title of "MyApp". But, navigation bar disappears when I click on Home
If I add a Navigation Bar in view controller, there will be 2 navigation bars at first run. One navigation will automatically disappear when I click on Home link.
How to do to get the first image appearance when I click on Home link? I'm using Swift 3.
You could try set the navigation bar to not hidden in the viewWillAppear.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(false, animated: false)
// ...
}
However I presume the reason the navigation bar is hidden is because the controller is being presented modally and not being pushed onto the main navigation controller. If this is the case, then you will need to probably do something with the SWRevealViewController and push the controller onto the main navigation controller.
Check out the Basic API usage for SWRevealViewController here and here is an alternative that has codeless storyboard implementation and is very easy to configure.
(Posted on behalf of the OP).
I'm not sure the way I solved is right or wrong. But, it works for me.
I remove default Navigation Bar by disabling the bar visibility. Then, I add new Navigation Bar in Home page. After I run the app, my new Navigation Bar appears when I press on the Home button.

Xcode: Missing navigation bar

One of my views does not display a navigation bar when it runs. From what I can see the attributes are exactly (unless I missed something) the same as other views that work properly.
None of the attributes on the view controller are set. Top Bar is Translucent nav bar.
I also checked the attributes on the Navigation Controller and they were the same, but in case I missed something I created a new one ... no difference. Bar visibility is checked along with Extend edges (top and bottom.)
I've cleaned and restarted Xcode
I haven't (intentionally) changed anything in the custom class for the view controller.
Obviously, I am missing something but what?

UISearchController always display scope bar

I am adding a search controller in my app that is part of a tab bar controller. I am trying to get the scope to always show, not just when the search bar is active. I have tried subclassing and overriding the method to always show it, and I have even tried using a UISearchBar and UISegmentedControl separate to seem like the scope is always showing. The issue with that is that the navigation bar height won't change. What would be the best/easiest way of doing this?
(also, for people who have used UISearchController, how can I get the background to extend under the status bar when the UISearchBar is active, like in the mail app)

How to identify the viewcontroller is clicked from More Tab or Separate tab in UITabBarController?

I have the navigationcontroller based viewcontroller and I overriding the root view controller navigation bar back button in to my custom segment control with different purpose. This navigation controller is placed one of the separate tab in the uitabbarcontroller. If this is used as the separate tab bar then no problem.
But if i use this navigationcontroller inside the more option in tabbarcontroller i am not able to come back to the more option list because of backbutton is overridden in my navigationcontroller.
My idea is add one back button only if my navigationcontroller is used more option tab otherwise i need to hidden the back button.
Please help me in this issue?
You can check if a view controller is in the 'more' section as follows:
BOOL isOnMoreNavigationController = [tabBarController.moreNavigationController.viewControllers containsObject:myViewController.navigationController];
From a UI consistency perspective it might be better to always show the back button in its standard position and move your custom buttons to some other place.

UINavigationController custom titleView

I have a navigation controller with a root view controller for which i have the customised titleView instead of normal title for the navigation item.
If i pushed a new controller in it , the default back button title is "back", Since i have used custome titleView.
I want it to be different. I tried by setting the title in backbaritem of the root view controller, but no use.
I can create a bar button item in my pushed controller and i can set it as leftbar item, But i want it like a normal back button. [Pointing towards backward]
Is it possible to set title for the back button , if i have a custom titleView ?
Is it possible to create a bar button item as like as default back button.[Pointing towards back , other than plain,border...etc] ?
Regards,
Balaji R.
I got it.
Even though i have custom titleView for my navigation item, I can still set the title for the same navigation item where it wont be taken for the title display in navigation item . but it will taken as the title of the back button when some other controllers are pushed into it.
So , Now i'm having both title [Used for back title display] and titleView [custom view] in the navigation item.
Thanks,
Balaji R.

Resources