简体   繁体   中英

Show top of screen when keyboard appears

I am making an activity as show in the following picture. 在此处输入图片说明

However when the user clicks the edittext at the bottom, the following happens. 在此处输入图片说明

How can I make it so that the top bar still shows even when the keyboard appears?

xml for the activity

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/CCLL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#303e73"
android:orientation="vertical">

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1.8"
    android:background="#303e73">


    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1.5">

        <ImageButton
            android:id="@+id/backbtn"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentTop="true"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"
            android:layout_toLeftOf="@+id/chatTV"
            android:layout_toStartOf="@+id/chatTV"
            android:background="#303e73"
            android:src="@mipmap/whiteback" />

        <TextView
            android:id="@+id/chatTV"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:text="Chats"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#FFFFFF"
            android:textSize="20dp"
            android:textStyle="normal" />
    </RelativeLayout>

    <RelativeLayout

        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">

        <TextView
            android:visibility="gone"
            android:id="@+id/typingTV"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1.5"
            android:text="LOL"
            android:textColor="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_alignTop="@+id/nameTV"
            android:layout_centerInParent="true" />

        <TextView
            android:id="@+id/nameTV"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_weight="1.5"
            android:text="Biker"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#FFFFFF" />
    </RelativeLayout>

    <RelativeLayout

        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1.5">

        <ImageButton
            android:id="@+id/optionsbtn"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#303e73"
            android:scaleType="centerCrop"
            android:padding="15dp"
            android:src="@mipmap/whitedot"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="41dp"
            android:layout_marginStart="41dp" />


    </RelativeLayout>


</LinearLayout>




<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight=".3">

    <ListView
        android:stackFromBottom="true"
        android:inputType="textMultiLine"
        android:maxLines="4"
        android:background="#26315c"
        android:id="@+id/messagesLV"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center_horizontal"
        android:transcriptMode="alwaysScroll"/>

</LinearLayout>




<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1.8"
    android:background="#303e73"
    android:orientation="horizontal">


    <ImageButton
        android:layout_gravity="center"
        android:id="@+id/addimgbtn"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:scaleType="centerCrop"
        android:padding="25dp"
        android:background="#303e73"
        android:src="@mipmap/whiteadd" />

    <EditText
        android:id="@+id/messageET"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight=".5"
        android:ems="10"
        android:textColor="#FFFFFF"
        android:textColorHint="#FFFFFF"
        android:background="#303e73"
        android:gravity="center"
        android:hint="Enter your Message..." />


    <ImageButton
        android:id="@+id/sendbtn"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:scaleType="centerCrop"
        android:padding="25dp"
        android:background="#303e73"
        android:src="@mipmap/whitesend" />

</LinearLayout>

Make it an actionbar and use in your manifest.xml:

android:configChanges="keyboardHidden|orientation|keyboard"
android:windowSoftInputMode="adjustResize"

make sure u don't use:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

Should work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM