0
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="6dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Opção de Pesq.: "
android:textColor="@color/black"
android:textSize="@dimen/font_size_normal" />
<Spinner
android:id="@+id/comboOpcaoPesqCliente"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:textSize="@dimen/font_size_normal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="6dp">
<EditText
android:id="@+id/edPesquisaCliente"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Digite para pesquisar"
android:imeOptions="actionDone"
android:singleLine="true"
android:textSize="@dimen/font_size_editText" />
<Button
android:id="@+id/btLimpar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Limpar"
android:textColor="@color/black"
android:textSize="@dimen/font_size_normal" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewListaClientes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:cacheColorHint="@android:color/transparent"
android:clipToPadding="false"
android:divider="@null"
android:dividerHeight="0dp"
android:listSelector="@android:color/transparent"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical" />
<ProgressBar
android:id="@+id/progressBar"
style="@android:style/Widget.ProgressBar.Large"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|center_vertical"
android:layout_marginRight="6dp"
android:visibility="invisible" />
</FrameLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
I added this to Activity in Manifest:
android:windowSoftInputMode="adjustPan"
What’s going wrong is this::
When I rotate the list down and the Toolbar hides and I click on an Edittext and the keyboard opens, then when I close the keyboard and scroll the list up, the Toolbar simply disappears, but this only happens when the keyboard opens when the Toolbar is hidden:
Photo: Before:
Afterward:
If you scroll the screen up, will Toolbar appear or will it remain hidden forever? I don’t understand why
LinearLayout
is with thebehavior
, only theRecyclerView
need to have it.– Wakim
This way I made the Toolbar works properly, if I scroll the list down the Toolbar appears, if I scroll the list up the Toolbar disappears. Only when the Toolbar is hidden and I open the keyboard and type something and close the keyboard, when I scroll the list down, the Toolbar appears, but it is all gray, like the photo I posted above. If I take the behavior from Linearlayout and put it into Recyclerview, Linearlayout is over the Toolbar. Recyclerview behavior image: http://i.stack.Imgur.com/Uldrp.png
– Rodrigo Lima
Rodrigo, I think it’s right to keep the
RecyclerView
. The problem in this case is the use ofandroid:fitsSystemWindows
. If you do not use theNavigationView
, is the case of taking these attributes from all views of this layout, which will solve this problem.– Wakim
I took android:fitsSystemWindows and changed the behavior from Linearlayout to Recyclerview and Linearlayout continued on the Toolbar
– Rodrigo Lima
Could it be the version I’m compiling? I’m using these: Compile 'com.android.support:appcompat-v7:22.2.0' / Compile 'com.android.support:design:22.2.0'
– Rodrigo Lima
I doubt it very much, but it is always good to use the latest versions (23.1.1 today). I will try to set an example here and reproduce the problem to be able to investigate better.
– Wakim
Man, if you could do that, I’d really appreciate it. I have been with this problem for a long time, but some more important things came up to do in the app and I put this aside, now that I have a little time left that I am resuming this. Vlw. I will edit the main post with full XML
– Rodrigo Lima
In a way I discovered the problem. The
LinearLayout
is below theAppBarLayout
because I asked to take the behavior (the behavior is who makes it stand below). Returning with the behavior in theLinearLayout
(without Recyclerview), keeping without the attributefitsSystemWindows
solves the problem?– Wakim
I did it like you said, then returned as it was before, Linearlayout does not stay on the Toolbar and the Toolbar works perfectly. But there is that problem of the keyboard being opened when the Toolbar is
– Rodrigo Lima
I recorded a video of what is happening: http://sendvid.com/gffll5yj . Note that the Toolbar only turns gray when the keyboard is opened when it is hidden, and then when I open the keyboard again it appears in normal color.
– Rodrigo Lima
I find it very strange, I do not know if it is a bug of the appcompat implementation. But here I did the same test (with a slightly simpler layout) and no problem. This layout is also very complex, I do not know if you simplify it to try to find the cause of the problem helps. Looking closer, I don’t think Toolbar is gray, he didn’t come back I guess.
– Wakim
What do you suggest to me to simplify the layout? I haven’t tried yet with version 23.1.1 , because I haven’t installed it here, so I’ll try to install it...
– Rodrigo Lima
The first thing that came to me is that it has a
LinearLayout
redundant vertical there, nested. It has some strange dimensions, like a guylayout_height=wrap_content
with a son beinglayout_height=match_parent
, in which case it would be nice to adjust too (it’s not good to have a fatherwrap_content
and sonmatch_parent
).– Wakim
I changed to version 23.1.1 and it worked, it was a bug of the previous version. Vlw..
– Rodrigo Lima
Pasta, could put a response commenting on this solution. Can help other people.
– Wakim