键盘打开时隐藏自定义操作栏

时间:2016-02-04 05:03:18

标签: java android xml android-actionbar

我在我的Activity布局中添加自定义操作栏,当键盘获得焦点屏幕变满并隐藏操作栏我正在使用 android:softWindowInput =" adjustPan" 属性Android Manifest,尝试了 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>    

任何帮助都可以提前感谢。

2 个答案:

答案 0 :(得分:1)

尝试在您的清单中使用android:windowSoftInputMode="adjustResize"来进行您的活动&#39;元素与还要在您的edittext属性中添加android:layout_alignParentBottom="true"

答案 1 :(得分:0)

检查您android:windowTranslucentStatus=trueapp的样式中是否使用activity theme

相关问题