안드로이드 스튜디오

coordinatorlayout ,appbar,Toolbar알아보기

담디비 2020. 6. 29. 13:40

fucking cooldinatorlayout

-어플의 최상위 docor View

-자식뷰들간의 특정한 interaction을 지원하는 컨테이너

 

자식뷰에 Behavior을 써줌으로써 하나의 부모안에 여러 다른 interaction을 지원할수있다 

그리고 자식뷰들간에도 서로 interaction 쌉가능 

 

기능이 여러가지있는데 나는 appbar 랑 toolbar 만 볼거임 

왜냐? 내지금 공부하고있는 프로젝트가 그것만 썻거등

 

 

<?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"
    android:id="@+id/MainLayout"
    android:background="@color/colorLightBeige"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:background="@color/colorWhite"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_height="wrap_content"
                android:layout_width="match_parent">
            </androidx.appcompat.widget.Toolbar>
            <LinearLayout
                android:paddingTop="16dp"
                android:layout_gravity="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <TextView
                    android:id="@+id/tv_levelTitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:textStyle="bold"
                    android:textSize="16sp"
                    android:text="토익목표점수">
                </TextView>
                <LinearLayout
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">
                    <TextView
                        android:id="@+id/tv_level"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="@color/colorAccentBule"
                        android:text="000점"
                        android:textSize="12sp"/>
                    <ImageButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="목표점수설정"
                        android:background="@drawable/ic_arrow_drop_down_black_24dp">
                    </ImageButton>
                </LinearLayout>
            </LinearLayout>
        </FrameLayout>

    </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">
        <FrameLayout
            android:layout_gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <com.github.ybq.android.spinkit.SpinKitView
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/spin_kit"
                style="@style/SpinKitView.CubeGrid"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:outlineSpotShadowColor="@color/colorAccentGreen"
                app:SpinKit_Color="@color/colorLigthtGray"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
            <include layout="@layout/contain_main"></include>

        </FrameLayout>
    </androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

 

 

 

anyway

안드로이드 스튜디오 개초보로써 appbar랑 toolbar을 처음 봤음

그래서 바아로 검색 고고씽 

 

그결과 .. 

 

원래는 액션효과 주는걸 appbar라고 하는데 이건 맨처음 부터 안드로이드에 있던 기능이고 

시간이 갈수록 여러가지 버전이많아지고 버전에따라 액션이 달라지는문제가발생

>>>>>So.. API21부터 toolbar가 등!장!  v7 appCompat 지원 라이브러리를 사용해 기기의 일관성확보 블라블라블라 

 

 

--사용법-- 

액션바는 액티비티 내부에 기본적으로 포함이 되어있어서 ㄱㅊ

xml에 액션바 위젯을 추가하지 않아도 테마가 appbar을 지원하면 사용가능

 

툴바쓸때에는 XML에 사용되는 다른뷰들이랑 똑같음. 그래서 사용할떄는 android.support.v7.widget.Toolbar 추가한다음 

Style 가서 NoActionbar 지정해줘야함  그리고  setSupportActionBar() 메소드 호출해주면 툴바를 액티비티의 앱바로 사용가능

 

(액티비티에서 툴바가 View 위젯으로 다루어진다는 것은 스타일 변경, 위치 조절, 애니메이션 등등에 이점 그리고 고정된 위치에 단 하나만 표시할 수 있는 액션바와는 다르게 툴바는 각각 분리된 영역에 여러개를 사용가능)

 

 

 

 

실행코드