简体   繁体   中英

Keyboard covers Edittext in Android Studio

I am trying to make edittext input for my app. I placed my edittext below recyclerview. However when touched edittext , keyboard opens and it covers edittext What i have tried:

I changed my manifest file and added:

android:windowSoftInputMode="adjustResize" attribute

and added:

android:fitsystemwindows=true to my root layout.

Activity_main

<androidx.drawerlayout.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:soundEffectsEnabled="true"
android:nestedScrollingEnabled="true"
android:fitsSystemWindows="true"
android:scrollbars="vertical"
android:verticalScrollbarPosition="left"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context=".Main2Activity"
tools:openDrawer="start">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/transparent"
        android:elevation="4dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeToolbar"
        app:popupTheme="@style/ThemeToolbar" />
    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:nestedScrollingEnabled="true"
        android:orientation="vertical" />

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    </FrameLayout>
</LinearLayout>

<com.google.android.material.navigation.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:scrollbarTrackVertical="@color/colorPrimary"
    android:soundEffectsEnabled="true"
    app:headerLayout="@layout/nav_header"
    app:menu="@menu/settings_menu" />

</androidx.drawerlayout.widget.DrawerLayout>

Fragment

<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_forum"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<Button
    android:id="@+id/send_forum"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:background="@android:drawable/ic_menu_send"
    app:layout_constraintBottom_toBottomOf="@id/createPost"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/createPost"
    app:layout_constraintTop_toTopOf="@+id/createPost" />

<EditText
    android:id="@+id/createPost"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    android:autofillHints=""
    android:gravity="top|start"
    android:hint="@string/mesaj_yaz"
    android:inputType="textMultiLine"
    android:lines="3"
    android:minLines="1"
    android:background="@drawable/send_message_background"
    android:scrollbars="vertical"
    android:textColorHighlight="@color/design_default_color_background"
    android:textColorHint="#1FAEC8"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/send_forum"
    app:layout_constraintStart_toStartOf="parent" />

<Button
    android:id="@+id/close_editing"
    android:layout_width="24dp"
    android:layout_height="24dp"
    android:layout_margin="8dp"
    android:visibility="gone"
    app:layout_constraintBottom_toTopOf="@id/createPost"
    android:background="@drawable/ic_cancel"
    app:layout_constraintStart_toStartOf="parent"
     />

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/forum_list"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:scrollbars="vertical"
    app:layout_constraintBottom_toTopOf="@+id/createPost"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0" />

<ProgressBar
    android:id="@+id/forum_progress"
    style="?android:attr/progressBarStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vfluygulamas">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:usesCleartextTraffic="true">
    <activity android:name=".LoginSystem.MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".DataBaseManagement.Main3Activity" />
    <activity
        android:name=".Main2Activity"
        android:windowSoftInputMode="adjustResize"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity android:name=".LoginSystem.RegisterActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>
</application>
 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);   
    Window w = getWindow();
    w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
            WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main2);

you should use Scrollview in your layout and set android:fillViewport="true" in your scrollview:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<androidx.constraintlayout.widget.ConstraintLayout 
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent">

  ...

</androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>

You have to add a constraint between the RecyclerView and the EditText .

This is an example:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView2"
        android:layout_width="132dp"
        android:layout_height="287dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/editTextTextPersonName"
        android:layout_width="214dp"
        android:layout_height="37dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Name"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/recyclerView2" />
</androidx.constraintlayout.widget.ConstraintLayout>



So, try to add :

app:layout_constraintEnd_toEndOf="parent"

Sorry,I didn't share MainActivity code, i have just edited question. The problem was that:

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

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