I have an activity that loads a fragments at runtime. When I start the application, the activity loads a fragment with an EditText. I use ActionBarSherlock with splitActionBarWhenNarrow so I have a split bar (an action bar at the botton of the screen). When the EditText get focus and the soft keyboard is loaded, it goes on top of the split bar, hiding it. On the action bar I also use NAVIGATION_MODE_LIST and I use the dropdown menu to load another fragment. When I load the other fragment, the lower action bar appears correctly on top of the soft keyboard, even if I go to the other fragment, at it keeps working correctly. I'll add some screenshot to clear it up:
First fragment loader, split bar not visibile with soft keyboard
After loading the second fragment using action bar navigation
Reloading another fragment, action bar still visibile
I tried with a test project with minimal code just to load the fragment and the behavior is the same, the split bar is hidden by the soft keyboard.
How can I make it show the split bar from the beginning?
Edit: android:windowSoftInputMode="adjustResize" doesn't change anything in this behavior
Activity layout:
<it.bem.remailr.MyFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_container"
android:orientation="horizontal"
android:background="#drawable/bg_no_repeat"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
Fragment layout:
<it.bem.remailr.MyRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top|left"
android:inputType="textMultiLine|textNoSuggestions"
android:windowSoftInputMode="adjustPan"
android:background="#00000000"
android:hint="#string/text_hint"
android:scrollHorizontally="false" >
</EditText>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
Have you tried posting a layout request to the main thread immediately following the input method being shown? You can determine whether the input method is shown/hidden by overriding the onSizeChanged() callback in your root View. As a dirty proof of concept, you could just post that layout request after a given duration (ensuring that you show the input method beforehand).
You could also use the ViewServer to run hierarchyviewer on your device, not emulator in order to determine what Views are present (that is, if the candidates are covering the split Action Bar). From what I remember though, the candidate views are added to the root Dialog that contains the KeyboardView anyway, so it's likely the split Action Bar is just under the space bar, as it were, rather than under the candidate view.
In order to implement onSizeChanged() you must extend the ViewGroup class that is at the root of your View hierachy. For example, you may have a LinearLayout as your root ViewGroup and all your Views are children of this. What you do then is create a new class called MyLinearLayout that extends LinearLayout, put MyLinearLayout as your root View in the xml file, and then implement the onSizeChanged() callback. It will then be called by the System when the input method is shown.
Related
I'm struggled with this for hours looking for solution on google and stackoverflow. Thought that this is some trivial bug in my app but finally made empty project and can reproduce this too. Just run new project and select "Tabbed Activity" with navigation style "Action Bar Tabs (with ViewPager)
Then try to put any widget at the bottom of the fragment's layout. I did this by modify fragment_main.xml and adding:
android:layout_height="match_parent"
android:gravity="bottom"
android:textAlignment="center"
So the whole layout is:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity$PlaceholderFragment">
<TextView
android:id="#+id/section_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:gravity="bottom"
android:text="aaaaaaa"
android:textAlignment="center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="#+id/constraintLayout"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
</android.support.constraint.ConstraintLayout>
In design mode everything looks fine:
But when you run app:
You will see text only when you swipe action bar to hide it:
So it is impossible to set widget at the bottom of the tab's fragment or even match some list/picture to the height of the parent because bottom edge will be always under navigation bar.
Workaround which I found is here:
ViewPager with Toolbar and TabLayout has wrong height
First one is to put AppBarLayout and ViewPager between LinearLayout but then I lose hidding action bar functionality when scrolling ViewPager's content. Second one is add android:paddingBottom="?attr/actionBarSize" in ViewPager but then there is a gap when I hide action bar. Seriously there is no solution for this?
I think this is an expected behavior since the ActionBar gets hidden when scrolling up. In the design mode the text can be shown because it doesn't display the TabLayout. However, when you launch the app, it will inflate the TabLayout and the fragment will go below it. So it's not like the fragment is getting expanded or giving you wrong height.
Imagine putting an ImageView that has a matching height of the visible field (from below the TabLayout to right above the navigation menu). When you hide action bar from there, it will have a gap on the bottom since there's no content to fill up the space of hidden action bar, unless you stretch the ImageView as you scroll up, which will result in wired stretched image :/
One possible solution I can think of is, if you want to add a view on the bottom of the fragment, I will set the actionbar padding to the view and when I scroll the screen, I will adjust the padding depends on the scroll offset so that I can always be on the bottom.
I'm trying to create an activity with a single RelativeLayout used as a fragment container, where each fragment has a separate background color that bleeds under a translucent status bar, and where the activity as a whole accounts for the keyboard size.
The layout for the activity is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
The fragments are wrapped with:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true" />
And the activity is defined as:
<activity android:screenOrientation="portrait"
android:name=".login.LoginActivity"
android:windowSoftInputMode="adjustResize" />
Everything is working fine for the first fragment. The activity resizes the RelativeLayout, the fragment contained within it resizes to adjust for the keyboard, and everything is fine. However, when replacing one fragment with another that uses <requestFocus /> on its <EditText />, the keyboard stays up but the second fragment that is pushed on takes the full screen size (under the keyboard). Closing and re-opening the keyboard causes the activity to re-measure and then everything is fine. Similarly, if the keyboard changes height during the fragment transition (when moving from a field that doesn't support autocorrection to one that does, so the keyboard gets taller), the fragment measures correctly. So it only appears to be a problem when transitioning between two fragments where the keyboard size is constant.
Adding fitsSytemWindows=true to the wrapping RelativeLayout fixes the problem, but also prevents the fragment's view from appearing under the status bar, which isn't what I want. Is there some way to force the fragment to re-measure or something that I'm missing? This is using native fragments, not app-compat.
I have a custom action bar for which I have used Sherlock Implementation and I tend to find that the tab widget is placed at the top every time rather than in the middle.
I have tried the following in XML but it seems to set the action bar at the top :
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
></TabWidget>
I want it somewhere in the middle. I have provided with an example image below :
As you can clearly see that the action bar is located at the top which is not what I want. So,how do I place it after the Followers list. Any ideas ??
Is the parent View of you TabWidget a LinearLayout? If so, you may try your luck with a RelativeLayout.
I am not quite sure what kind of layout Gmail is using in Android.
I suppose they use a floating ViewGroup.
But for the menu on the top and bottom I really need somebody point me how to make that.
I suggest you to use the Sherlock ActionBar:
http://actionbarsherlock.com/
This allows you to easily develop an application with an action bar for every version of Android from 2.x and up.
In the sample app you can find the code to achieve what you are looking for under "Split Action Items". The idea is that you add actions from the menu as usual, but writting the following line in your manifest activity:
android:uiOptions="splitActionBarWhenNarrow"
You can create a menu which will sit on the bottom of a listview using the <RelativeLayout> tag like so
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ListView
android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="#android:id/list"
android:listSelector="#android:color/transparent"
android:layout_above="#+id/footer" />
<include android:id="#+id/footer" android:layout_height="wrap_content"
layout="#layout/mymenu" android:layout_width="fill_parent"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true" >
</include>
</RelativeLayout>
mymenu will contain a linearlayout with something like a tablelayout with a few rows (which can be textviews, imageviews, etc.) The table will sit at the bottom of your screen and the listview will be in a frame which starts at the top of the screen and ends at the top of the menu (no overlap)
You could also do the same for the top of the screen by simply having the listview say layout_below="#+id/header" instead of layout_above"#+id/footer" (or do both!)
This is covered on android. You have to implement a "split action bar". Note that it works in potrait view and disappears when you switch to landscape.
Android Action Bar
It looks like a custom ActionBar implementation. If you put icons in a normal ActionBar and there is not enough space to display them, android creates a bottom bar on its own and display the icons there.
I had a similar application and I chose to put my own custom bar there instead of implementing ActionBar
I have a rather trivial question, but I thought I'd give it a shot. I'm writing an android app and I have a viewgroup form that is loaded from a web server. While the internet access is running, I used to pop up a dialog box with a progress bar. I decided it would look less clunky if I swtiched to the nice small indeterminate progress bar in the title bar.
The title bar option does look less busy, except that the form items (textviews, buttons etc) are all enabled during the retrieval. I then used a recursive routine to disable all the views in the viewgroup, but that again looks ugly - the greyed out textviews (2.3.3) look gross, especially the one with the focus with the orange bar around it. If I pop up a progress bar, the underlying view looks nicely disabled - the window behind is simply slowly dimmed down. From a visual point of view, it much more obvious that we're waiting for something to occur when the entire window is dimmed rather than being faced with a bunch of disabled controls.
Is there a call I can make to disable a view in a similar way the OS does when a progress bar or other window is overlapped on top? This would give me the best of both worlds.
I guess the other option is to set the view to invisible during the access, but I got curious because I can see the OS doing exactly what I want when I use the popup.
I figured out how to do this using a relative layout with a progress dialog wrapped in a frame layout overlapping the main view. When I do my network get, I set the visibility of the frame layout to visible with the background set to translucent, and disable the controls in the underlying view. Works pretty well.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ScrollView
android:id="#+id/itemView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ScrollView>
<FrameLayout
android:id="#+id/itemProgress"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#55000000"
android:visibility="gone"
>
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center|center_vertical"
android:indeterminateOnly="true"
/>
</FrameLayout>
</RelativeLayout>