隐藏工具栏焦点EditText问题

时间:2015-07-06 19:26:32

标签: android xml

我在聊天活动中的应用程序中使用了android.support.v7.widget.Toolbar。但是只要EditText焦点和键盘打开,工具栏就会隐藏。

这是我的xml代码: app_bar.xml

<?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="?android:attr/actionBarSize"
android:background="@color/primaryColor"
android:minHeight="?attr/actionBarSize"
app:theme="@style/myCustomToolBarTheme"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" >

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

activity.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="#ccc"
android:orientation="vertical" >

<include
    android:id="@+id/app_bar"
    layout="@layout/app_bar" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/app_bar" >

        <ListView
            android:id="@+id/my_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:ems="10" >

            <requestFocus />
        </EditText>
    </RelativeLayout>

</RelativeLayout>

输出屏幕:

enter image description here enter image description here

请帮帮我。

2 个答案:

答案 0 :(得分:2)

据我所知,你的问题是什么,我认为当你尝试在这个编辑文本中输入内容时,你的布局就会向上移动。所以我的解决方案是: 在单个布局中包装除工具栏之外的所有内容并放入scrollview中。 然后工具栏将保留,页面内容将在您输入时滚动。 试试这段代码:

<include
        android:id="@+id/app_bar"
        layout="@layout/app_bar" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/app_bar"
    android:fillViewport="true">

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="@string/second_activity"
            android:textColor="#000"/>

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:ems="10">

            <requestFocus/>
        </EditText>
    </RelativeLayout>
</ScrollView>

答案 1 :(得分:0)

只需设置

  <item name="android:windowFullscreen">false</item>

样式。然后将视图置于滚动视图下。

相关问题