2015-07-06 3 views
2

Я использую android.support.v7.widget.Toolbar в своем приложении в чате. Но как только EditText фокусируется и открывается клавиатура, панель инструментов скрывается.Скрыть панель инструментов в фокусе EditText issue

Это мой 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

Насколько я знаю, в чем проблема, я думаю, что ваш макет просто движется вверх, когда вы пытаетесь ввести что-то в этот текст редактирования. Итак, мое решение: Оберните все, кроме панели инструментов, в одном макете и введите в 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> 
+0

Спасибо за ваш ответ, но можете ли вы отправить здесь практический код. –

+0

Проверьте измененный ответ. –

+0

Спасибо за ваши усилия, но все же он не работает. –

Смежные вопросы