안드로이드 자바
[JAVA][Android]사라지는 AppBar 구현하기
teamnova
2022. 2. 5. 12:00
728x90
- AppBar는 현재 화면의 타이틀을 포함하고, 위 그림에서 볼 수 있는 좋아요(하트 버튼) 버튼, 검색 버튼, 더보기 버튼 등 현재 화면에서 사용자가 할 수 있는 다양한 action을 담고 있는 막대 모양의 뷰이다.
- 현재 화면의 타이틀을 나타내거나, 현재 화면에서 사용자가 할 수 있는 다양한 action(좋아요, 검색, 더보기 등)을 구현하기 위해서 사용한다.
1. android:Theme에 NoActionBar 설정하기
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
2. xml 작성하기
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="toolbar"
app:layout_scrollFlags="scroll|snap|enterAlways">
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="350dp"
android:text="하하하"
android:background="@color/purple_200"/>
<TextView
android:layout_width="match_parent"
android:layout_height="350dp"
android:text="하하하"
android:textSize="20dp"
android:background="@color/black"
android:textColor="@color/white"/>
<TextView
android:layout_width="match_parent"
android:layout_height="350dp"
android:text="하하하"
android:textSize="20dp"
android:background="@color/purple_700"
android:textColor="@color/white"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
3. 실행하기
스크롤이 올라가면 위의 앱바가 안보입니다.