#java #android #xml #android-studio #android-layout
#java #Android #xml #android-studio #android-макет
Вопрос:
Я пытаюсь ввести edittext для своего приложения. Я разместил свой 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);
Ответ №1:
вы должны использовать Scrollview в своем макете и установить android:FillViewport=»true» в вашем 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>
Комментарии:
1. это видео на YouTube youtube.com/watch?v=FOibPikr0qc может помочь вам
2. Я смотрел это видео, но все еще нет: (
Ответ №2:
Вы должны добавить ограничение между RecyclerView
и EditText
.
Это пример:
<?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);