我在我的活动布局中添加自定义操作栏,当键盘使焦点屏幕变满并隐藏操作栏时,我正在Android清单中使用android:softWindowInput =“ adjustPan”属性,并尝试了android:softWindowInput =“ adjustResize”但操作栏没有隐藏,但键盘隐藏了EditText。以下是XML布局。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/tile_bg">

<!-- Top bar-->
<include
    android:id="@+id/app_bar"
    layout="@layout/app_bar_chat" />
<!-- Chat Messages-->
<ListView
    android:id="@+id/lvChats"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/app_bar"
    android:divider="@null"
    android:scrollingCache="true"
    android:smoothScrollbar="true"
    android:layout_above="@+id/llMsgCompose" />

<!-- bottom layout for chat msg compose-->
<RelativeLayout
    android:id="@+id/llMsgCompose"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/translucent_black"
    android:padding="2dp"
    android:visibility="visible">
    <!-- Mic button-->
    <RelativeLayout
        android:id="@+id/rl_Mic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:background="@drawable/circle_red"
        android:gravity="center"
        android:padding="@dimen/pad_5dp">

        <ImageView
            android:id="@+id/iv_Mic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@drawable/ic_mic"
            android:textColor="@color/white" />

    </RelativeLayout>
    <!-- Play button - It will get visible once the user press stop button-->
    <RelativeLayout
        android:id="@+id/rl_Play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginLeft="@dimen/pad_5dp"
        android:background="@drawable/circle_red"
        android:gravity="center"
        android:padding="@dimen/pad_5dp"
        android:visibility="gone">

        <ImageView
            android:id="@+id/iv_play"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@drawable/ic_play_recording"
            android:textColor="@color/white" />

    </RelativeLayout>
    <!-- Show recording time -->
    <Chronometer
        android:id="@+id/chronometer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textColor="@color/red"
        android:textSize="@dimen/txt_20sp"
        android:textStyle="bold"
        android:visibility="gone" />

    <EditText
        android:id="@+id/et_ChatMsg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="@dimen/pad_5dp"
        android:layout_marginRight="@dimen/pad_5dp"
        android:layout_toLeftOf="@+id/rl_Send"
        android:layout_toRightOf="@+id/rl_Mic"
        android:background="@color/white"
        android:ellipsize="end"
        android:gravity="center_vertical"
        android:hint="@string/et_chat_msg"
        android:padding="@dimen/pad_10dp"
        android:singleLine="true"
        android:textStyle="normal"
        android:imeOptions="flagNoExtractUi"
        />
    <!-- Send button-->
    <RelativeLayout
        android:id="@+id/rl_Send"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:background="@drawable/circle_red"
        android:gravity="center"
        android:padding="@dimen/pad_5dp">

        <ImageView
            android:id="@+id/iv_Send"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@drawable/ic_send"
            android:textColor="@color/white" />

    </RelativeLayout>
</RelativeLayout>

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/scrollView"
    android:layout_alignTop="@+id/lvChats"
    android:layout_alignParentEnd="true" />
</RelativeLayout>


我的自定义操作栏如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar     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="80dp"
android:background="@color/red"
android:fitsSystemWindows="true"
app:popupTheme="@style/Theme.AppCompat">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/ivHeaderLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginRight="@dimen/pad_5dp"
        android:background="@drawable/ic_dialog_logo"
        android:visibility="gone" />

    <TextView
        android:id="@+id/tvScreenHeading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/ivHeaderLogo"
        android:text="@string/chat_header_bar"
        android:textColor="@android:color/white"
        android:textSize="20sp"
        android:visibility="visible" />


</RelativeLayout>

 </android.support.v7.widget.Toolbar>


在此先感谢任何帮助。

最佳答案

尝试在清单中使用android:windowSoftInputMode="adjustResize"作为“活动”元素,并在您的edittext属性中添加android:layout_alignParentBottom="true"

关于java - 自定义操作栏在键盘打开时隐藏,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35192877/

10-12 03:03