I have a main activity with content - a WebView.
Basically, when the user opens the application, I do a quick check if they are logged in. If they aren't logged in, then I inflate the login fragment.
At this point, you get a flicker of the WebView underneath before the fragment is inflated. It's a little bit clunky. It has made other things worse by the fact that I have to hide/show the actionbar in the same step.
Is there any solution to get around this? I guess I can hide my WebView until needed, but the actionbar will still be shown for a moment. Any suggestions for this problem?
Related
I am creating an app in Kotlin. The desired operation is that when the user opens the app, the user will be presented with a menu offering navigation options. Upon tapping one of the icons, the user will then be presented with another menu. From that menu, several things can happen. This works fine in my app. The problem comes when I add ViewPager2. I would like the user to have multiple "pages" open at the same time that the user can switch between. Each page will start at the Main Menu and then move on as stated above. To simplify this, I'm trying to build something similar to a web browser. The user can have multiple pages, tabs, or whatever open which are independent of each other and can switch between them at will
Scrolling between pages in ViewPager2 is where most of my problems have happened. Here is what I have tried so far:
Loading each fragment into a "holder" fragment - The Fragment disappeared when scrolling to another fragment.
Letting the Main Activity load the Main Menu Fragment without a "holder" fragment. This worked for scrolling between pages, but when I tap on a menu icon on any page, it changed the data on the first page.
I tried using SupportFragmentManager and ChildFragmentManager. I tried to mix the two with varied results. None of which create the desired behavior.
Am I using ViewPager2 as it was intended or is there something else that I should be using to accomplish what I'm trying to do?
I have an application where it is required to persist the bottom navigation across multiple screen. Now naturally bottom navigation works well with fragments but the problem is that my other fragments also have other screens to call which is usually delegated back to the handling activity.
With said, when i tried implementing the bottom navigation with fragments the activity becomes a God Activity where it handles all fragments.
So my solution was to start an activity instead. But the problem with this approach is that every start of the activity the activity transition makes it obvious an activity is being started. I tried setting off the activity transition to avoid this but now Im left with a very static page which just suddenly changes. I still want my views to animate smoothly between screen changes.
Can someone give me an advice here. Heres what I would want to achieve in summary:
1) make it seem the bottom navigation was not changed/moved (and hopefull still have the shifting animation if possible)
2) animate smoothly between screen changes
3) also still have the capability of having shared element transition if possible.
Please help me here. Thank you so much in advance.
I want to add a login window on top of my main fragment and close it after user logs in. The login window should be smaller than the screen size so main fragment should be visible in the background. It should be impossible to close the window in any other way than logging in. I am thinking about adding a relative layout where login table should be displayed on top of the main fragment, and be hidden after user logs in. However, this does not look like an elegant solution to me. Is there a better way to achieve this?
Alert dialog will work, but best practices say you should just have a login fragment they cant get past. making it look like its an overlay is possible too, with a screenshot of you app as the background
My Action bar consists of two tabs (a list of businesses and a map of businesses). If someone chooses from the list I would like to hide the tabs and show that business' page. If the user hits back, the business fragment is popped and the tabs should be displayed again.
What is the best approach to get this working? So far with the following code I have an inexplicable recursive loop if I pop the business fragment :(
So picture this, I'm displaying the BusinessListFragment tab. I choose a business, swap fragments and in onPause() I set the navigation mode to standard. Hit the back key, and in the onResume() of the BusinessListFragment I have this:
ActionBar ab = mHostingActivity.getSupportActionBar();
if (ab.getNavigationMode() == ActionBar.NAVIGATION_MODE_STANDARD)
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Which is supposed to bring back the tabs, but the app freezes with a loop. The tabs are definitely still present. Maybe I'm doing something else strange in my code (I'm sure I'm not though), or maybe Android does something strange when the naviagtion mode is set?
Edit: I've learnt that simply setting the navigation mode to tabs seems to actually select the first tab - which I believe would explain the recursion. Interesting!
Okay well this took a while to figure out but hopefully this will help future googlers :D
It seems the best practice is to never try and hide / show tabs by setting the navigation mode from within a tab fragment's onResume / onPause, or anywhere within it for that matter.
I therefore set the mode to Standard in the onResume() of the detail (business) fragment. Normally if there are no more hierarchical layers of navigation to traverse from within the detail fragment, it is fine to simply set the mode back to Tabs in the detail fragment's onPause() - accounting for back presses or up presses.
However in my case you can click on elements within the business page to launch another fragment (leaving a stack count of 3), meaning I cannot 'turn on' tabs within onPause(), and found the best solution was to do it within onDetach(). This should mean the tabs are only turned on when the detail fragment is actually popped from the stack.
Hopefully this solution is accurate, I have toyed with many ideas including back stack listeners and overriding onBackPressed, but for me this seems to be the best option.
i've got a tabbed layout, and on one of the tabs i have a search functionality. When the user makes a new search, i need to show the results. However, doing so involves starting another activity to handle the search results.
this causes the tabs at the bottom to disappear. The user can get the tabs back by clicking on the 'back' button. But somehow, in the context of my application this can be a bit counter-intuitive and seems to be break the common layout flow.
is there any way to prevent the tabs from disappearing when invoking the search from one of the tabs?
thanks for any help/suggestions.
as far as i can understand your problem, You are not using tabs then you are using buttons. see some tabhost tutorials on how to create a tabbed activity. what you are doing is launching a new activity instead of just switching a tab in the existing one.
Also the other things you can look for are activity groups.
Hope this helps you somehow.