【问题标题】:Keyboard covers Edittext in Android Studio键盘覆盖 Android Studio 中的 Edittext
【发布时间】:2020-10-09 16:11:51
【问题描述】:

我正在尝试为我的应用程序进行编辑文本输入。我把我的edittext放在recyclerview下面。 但是,当触摸 edittext 时,键盘会打开并覆盖 edittext 我尝试过的:

我更改了清单文件并添加了:

android:windowSoftInputMode="adjustResize" 属性

并添加:

android:fitsystemwindows=true 到我的根布局。

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>

片段

<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 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);

【问题讨论】:

    标签: java android xml android-studio android-layout


    【解决方案1】:

    您应该在布局中使用 Scrollview 并在您的滚动视图中设置 android:fillViewport="true":

    <?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>
    

    【讨论】:

    【解决方案2】:

    您必须在RecyclerViewEditText 之间添加一个约束。

    这是一个例子:

    <?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>
    



    所以,尝试添加:

    app:layout_constraintEnd_toEndOf="parent"
    

    【讨论】:

      【解决方案3】:

      抱歉,我没有分享 MainActivity 代码,我刚刚编辑了问题。问题是:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多