My app is based on the single activity architecture, and I have a parent fragment inside the activity which has a navigation bar at the bottom and a frame layout on which I place other child fragments.
One of the child fragments has an EditText at the bottom, but when the soft-keyboard is up, I want that the view is only adjusted of the child fragment.
I have already tried adjust pan or resize options but nothing is working for this specific use case.
When I use the following code, it adjusts the EditText but the bottom bar of the parent fragment also goes up when keyboard is shown, which is not what I am trying to do.
requireActivity().window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN or WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
Any help will be appreciated.
Related
I am using coordinator layout with tabs, some of which (the tabs) contain a recycler view whilst some don't. All the tabs contain a floating action button. On scrolling the recycler view with the in one of the tabs, the floating action button is scrolled off by the coordinator layout. However, when I switch to the tab without the recycler view, and not being able to scroll, the tab remains scrolled off the screen (as it was done in the tab with a recycler).
How do I bring back the floating action button back when there is no way of scrolling in the tab without the recycler or any scroll mechanism?
Turned out to be a simply solution of translating the fab back in. floatingActionButton.setTranslationY(0.0f);
This is the problem I have: https://imgur.com/a/GKZpdX9
The AdView that I have anchored to the bottom of the layout will be slightly pulled out of place and will only come back to its intended place when the user scrolls through the RecyclerView again.
The activity uses two fragments, one for the banner at the bottom and another one on top for the rest of views so when the user clicks a ViewHolder the upper fragment is replaced.
I have tried to use methods such as .scrollToView to force the RecyclerView to move, but it kept the misplacement of the banner. ONLY when the user does scroll comes back into the right place.
I have checked that if instead of replacing the upper fragment the user was taken to a different activity and then the back button was pressed, this problem would not happen. But I need to use a fragment.
Instead of creating seperate fragment for banner in Activity. you should use this code technique in your fragmentActivity. use relative layout for top view in activity then add bannerView with specific height and set alignParentBottom to true. then add another layout which contain your recyclerview fragment and set this property (layoutAbove and pass the addview id to id). it will place exact top of the banner.
Let me brief about my idea and what I'm aiming to achieve,
Idea is to have a swipe tab with three tabs in it and each tab screen being represented by a seperate Fragment class. I did this using the "it.neokree:MaterialTabs:0.11" library and everything is working well.
Then I created a floating action button (FAB) using the "com.oguzdev:CircularFloatingActionMenu:1.0.2" library.
Now what I'm trying to achieve is to fix this FAB to the fragment in the center tab and when I swipe the screen to go the previous or the next tab the FAB should slide out along with the tab fragment its in and should slide back in along with the center tab screen when I swipe back to it.
I have worked on it till now and now I'm able hide the view in other fragments and show it again in the center fragment by overriding the setUserVisibleHint() method in each fragment class like this.
#Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
View tempView = getActivity().findViewById(R.id.myFAB);
tempView.setVisibility(View.INVISIBLE);
}
}
But the problem is I want the FAB to slide out and in along with the center tab just like other views in the tab's fragment class does, but my FAB is simply vanishing and reappearring.
In a way I want the FAB to be exclusive to the center tab and should be fixed to it.
I also tried defining the FAB inside the center Fragment class but it doesn't seem to make any difference. Any Advice and suggestion will be very helpful. Thanks in advance
This library adds it's view to the 'android.R.id.content' ViewGroup. That's why it doesn't matter, where you define it.
Animating such view may be difficult, but should be possible. You have translate the FAB while swiping the pager manually.
By the way, Google recommends to hide the FAB, not swipe:
For tabbed screens, the floating action button should not exit the
screen in the same direction as the screen exits. Doing so creates
visual noise. It would also cause a nonfunctional floating action
button to appear on screen. Furthermore, it incorrectly implies that
the floating action button is at the same the z-level as the content,
rather than at the level of the primary UI elements at the root
level.
See: http://www.google.com/design/spec/components/buttons-floating-action-button.html#buttons-floating-action-button-behavior
If you want to show the FloatingActionButton only in the middle/single tab, then you can add the FAB in the Fragment instead of adding it in Activity in which all the Fragments are added.
I'd love to know if anybody knows how to achieve following:
I've got a ViewPager showing up a fragment. While this fragment is showing, You can see the small left border of the fragment to the right. This fragment can be pulled out and acts like a NavigationDrawer.
Here's an example, the Android L Calculator app:
https://d13yacurqjgara.cloudfront.net/users/409459/screenshots/1647461/calculatorrender.gif
As You can see, there is a small blueish border to the right which can be pulled out by swiping it in just like a NavigationDrawer.
Any suggestions how this is achieved?
From the looks of it, this is not done with a ViewPager.
If I would have to do this layout, I would do it with 2 ViewGroups next to each other.
The first one would take 90% width of the screen, would be in the back, and aligned to the left, lets call this layout A.
The second one would take 75% width of the screen, placed in the front, aligned to the right, and have right margin of -65%. I would also add a nice shadow to its left edge, and call it layout B.
Layout A would have a grey background and lots of buttons, as in the animation. If the user swipes left on this view, you set a flag that layout B is shown, and animate the right margin of layout B, to show it. You would do the same when layout B is tapped while being almost hidden.
Any tap on layout A now would close layout B (you can control this with the flag).
When tapped on a button in layout B, you also animate the right margin back, and set the flag also back to false.
If you would use fragments for this, then you would have to worry too much with the communication between the two, and it would just go the same way as with views.
I am using same activity for multiple fragments. every fragment there is a searchview. Except home fragment in all other fragment we display listviews. In home fragment i have linear layouts to display some buttons and footer view. And when i type something in searchview in the home fragment it will display listview.i want to resize my screen when keyboard is up. So i have used below mentioned tag in manifest file for the actvity.
android:windowSoftInputMode="adjustResize"
It is wokring fine in all the fragments except home fragment. In home fragment when i tap on searchview(before typing.ie still displaying the buttons) the screen including the footer view is up. No issues with layout contains buttons. becuase it is scrollable. But topmost layout is not visible fully. Is it possible to stop it from pushing the footer layout to top in this fragment?