반응형
EditText 포커싱 될 때 키보드가 EditText를 가리는 문제
(CoordinatorLayout 안에 scrollview 안에 EditText 가 있음.)
아래처럼 적용하면 키보드가 화면을 밀어내면서 가리지 않게 된다.
AndroidManifest 에 windowSoftInputMode 추가
android:windowSoftInputMode="adjustPan|stateAlwaysVisible|stateVisible"
(예시)
<activity
android:name=".DreamDetailActivity"
android:theme="@style/Theme.DetailPage"
android:windowSoftInputMode="adjustPan|stateAlwaysVisible|stateVisible" />
(전체코드)
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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/dreamdetail_coordinatorlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".DreamDetailActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/dreamdetail_appbarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="@android:color/white"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:scrimAnimationDuration="400"
app:statusBarScrim="@android:color/transparent">
<ImageView
android:id="@+id/dreamdetail_imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleX="2"
android:scaleY="2"
android:tintMode="src_atop"
android:translationY="-60dp"
app:layout_collapseMode="parallax"
app:srcCompat="@drawable/discover_career_01_getajobatmydreamcompany"
app:tint="#40000000" />
<ImageButton
android:id="@+id/dreamdetail_backbutton"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_margin="20dp"
android:background="@null"
android:scaleType="centerCrop"
android:src="@mipmap/arrow_left_white"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="1" />
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/dreamdetail_description_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginHorizontal="20dp"
android:layout_marginBottom="20dp"
android:background="@android:color/transparent"
android:hint="Typing..."
android:maxLines="8"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textSize="30sp"
app:layout_collapseMode="parallax" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
<com.google.android.material.tabs.TabLayout
android:id="@+id/dreamdetail_tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F9F9F9">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Overview" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Habit" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Task" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Note" />
</com.google.android.material.tabs.TabLayout>
</com.google.android.material.appbar.AppBarLayout>
<!--NOTE 스크롤 하면서 앱바를 감추고 싶다면 layout_behavior를 "@string/appbar_scrolling_view_behavior"로 설정해야함! -->
<androidx.core.widget.NestedScrollView
android:id="@+id/dreamdetail_nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F9F9F9"
android:overScrollMode="never"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="300dp"
android:orientation="vertical">
<TextView
android:id="@+id/dreamdetail_category_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Category"
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/dreamdetail_category_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="10dp"
app:cardElevation="0dp"
app:strokeColor="#F3F3F3"
app:strokeWidth="1dp">
<TextView
android:id="@+id/dreamdetail_category_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingVertical="18dp"
android:paddingStart="20dp"
android:text="Wealth"
android:textColor="@color/black" />
</com.google.android.material.card.MaterialCardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Due date"
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/dreamdetail_duedate_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="10dp"
app:cardElevation="0dp"
app:strokeColor="#F3F3F3"
app:strokeWidth="1dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingVertical="18dp"
android:paddingStart="20dp">
<ImageView
android:id="@+id/dreamdetail_duedate_imageview"
android:layout_width="18dp"
android:layout_height="18dp"
android:src="@mipmap/duedate"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/dreamdetail_duedate_date_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:includeFontPadding="false"
android:text="18 Nov, 2022"
android:textColor="@color/black"
android:textSize="14sp"
app:layout_constraintStart_toEndOf="@+id/dreamdetail_duedate_imageview"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/dreamdetail_duedate_dday_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="D-1412 days"
android:textColor="#929292"
android:textSize="10sp"
app:layout_constraintStart_toStartOf="@+id/dreamdetail_duedate_date_textview"
app:layout_constraintTop_toBottomOf="@+id/dreamdetail_duedate_date_textview" />
<ImageButton
android:id="@+id/dreamdetail_duedate_delete_imageview"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginEnd="15dp"
android:src="@mipmap/x_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Dream Reminder"
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/dreamdetail_reminder_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="10dp"
app:cardElevation="0dp"
app:strokeColor="#F3F3F3"
app:strokeWidth="1dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingVertical="18dp"
android:paddingStart="20dp">
<ImageView
android:id="@+id/dreamdetail_reminder_imageview"
android:layout_width="18dp"
android:layout_height="18dp"
android:src="@mipmap/reminder"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/dreamdetail_reminder_time_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:includeFontPadding="false"
android:text="04:00 PM"
android:textColor="@color/black"
android:textSize="14sp"
app:layout_constraintStart_toEndOf="@+id/dreamdetail_reminder_imageview"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/dreamdetail_reminder_date_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="18 Nov, 2022"
android:textColor="#929292"
android:textSize="10sp"
app:layout_constraintStart_toStartOf="@+id/dreamdetail_reminder_time_textview"
app:layout_constraintTop_toBottomOf="@+id/dreamdetail_reminder_time_textview" />
<ImageButton
android:id="@+id/dreamdetail_reminder_delete_imageview"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginEnd="15dp"
android:src="@mipmap/x_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/dreamdetail_habit_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="0.3"
android:text="Habit"
android:textAllCaps="true"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/dreamdetail_habit_add_button"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginEnd="12dp"
android:background="@null"
android:src="@mipmap/dreamdetail_add"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/dreamdetail_habit_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:overScrollMode="never" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/dreamdetail_task_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="0.3"
android:text="Task"
android:textAllCaps="true"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/dreamdetail_task_add_button"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginEnd="12dp"
android:background="@null"
android:src="@mipmap/dreamdetail_add"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/dreamdetail_task_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:overScrollMode="never" />
<TextView
android:id="@+id/dreamdetail_note_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:letterSpacing="0.3"
android:text="Note"
android:textAllCaps="true"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="10dp"
app:cardElevation="0dp"
app:strokeColor="#F3F3F3"
app:strokeWidth="1dp">
<com.google.android.material.textfield.TextInputEditText
android:background="@null"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Add more info"
android:paddingHorizontal="20dp"
android:paddingVertical="18dp" />
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
반응형
'프로그래밍 > App 개발' 카테고리의 다른 글
[Android] Custom DialogFragment EditText keyboard 가림 (0) | 2022.01.27 |
---|---|
[Android] Android Studio 가장 위로/아래로 커서 이동 단축키 변경 (2) | 2022.01.14 |
[Xamarin] Custom sliver top area (gradually disappearing view while scrolling) (0) | 2021.09.13 |
[Xamarin] set alpha at hex (0) | 2021.06.16 |
[C#, Xamarin] Call by value, deep copy (0) | 2021.06.16 |