I use a viewpage to view fragment, which are switched by tabs.
This is my fragment_details_comment.xml
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/chat_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
tools:context=".activities.DetailsActivity">
<ListView
android:id="@+id/comments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="8dp"
android:paddingBottom="4dp"
android:layout_marginBottom="4dp"
android:clipToPadding="false"
android:divider="@drawable/chat_divider"
android:scrollbarStyle="outsideOverlay"
android:layout_above="@+id/bottomlayout"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"/>
<TextView android:id="@+id/no_comments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/no_comments"
android:textAlignment="center"
android:layout_marginTop="10dp"
android:textSize="18sp"/>
<LinearLayout
android:id="@+id/bottomlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_marginBottom="8dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minHeight="50dp"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:paddingBottom="15dp"
android:paddingStart="12dp"
android:paddingEnd="20dp"
android:background="@drawable/input">
<ImageView
android:id="@+id/emoji_button"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="bottom"
android:src="@drawable/ic_tag_faces_white"
android:tint="@android:color/darker_gray"/>
<EditText
android:id="@+id/comment_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="12dp"
android:hint="@string/type_your_message"
android:inputType="textMultiLine"
android:textSize="18sp"
android:textColorHint="#c4c0bd"
android:background="@null"/>
</LinearLayout>
<ImageButton
android:id="@+id/send_comment"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:background="@drawable/input_circle_normal"
android:src="@drawable/ic_send_white"/>
</LinearLayout>
</RelativeLayout>
And this the activity_details.xml
file:
<?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"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.mysampleapp.details">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
android:id="@+id/appbar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="@android:color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="250dp"
class="com.google.android.gms.maps.SupportMapFragment" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_gravity="start"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_save_white" />
</android.support.design.widget.CoordinatorLayout>
(The fab is hidden in the fragment_details_comment.xml
and only shown in the other fragment!)
When I touch on the EditText field, my keyboard is shown and is displayed on top of my content.
So I googled, how to change that.
So I found this: How to move the layout up when the soft keyboard is shown android
I placed this line of code into my Android Manifest file and placed it inside my activity config:
<activity
android:name=".activities.DetailsActivity"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan|adjustResize">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.MainActivity" />
</activity>
That didn't work, nothing changed at all.
Then I tried another answer: https://stackoverflow.com/a/15063495/2977288
This does work partly: I moves up my content, but also my toolbar and my tabs I'm using. Additionally the content is not completely moved up, so something like 20dp are still covered by the keyboard
Is it maybe because of the fragment or the viewpage?