본문 바로가기
프로그래밍 놀이터/안드로이드, Java

[android] Material Support Library

by 돼지왕 왕돼지 2017. 7. 8.
반응형

 [android] Material Support Library


http://code.hootsuite.com/tips-and-tricks-for-android-material-support-library

https://android-developers.googleblog.com/2014/10/material-design-on-android-checklist.html


'com.android.support:appcompat-v7, actionbaractivity, Android, android:showAsAction, android:statusBarColor, android:windowDrawsSystemBarBackgrounds, android:windowNoTitle, app theme, app:popupTheme, app:showAsAction, app:theme, build.gradle, coloraccent, colorprimary, colorprimarydark, Compile, custom layout, dependency, drawerlayout, fitsSystemWindows, fragment, fragmentactivity, getActionBar, getfragmentmanager, getSupportActionBar, getSupportFragmentManager, Gingerbread, material support lib, material support library, NoTitleBar, PreferenceFragment, StatusBar, statusbarcolor, support fragment, theme.appcompat, theme.appcompat.light.darkactionbar, Toolbar, windowActionBar, [android] Material Support Library


-

material support lib 을 사용하기 위해서는 build.gradle 에 dependency 를 추가해주어야 한다.


dependencies {

    compile 'com.android.support:appcompat-v7:21.0.+'

}



-

App theme 도 바꿔주자.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

  <item name="colorPrimary">@color/primary</item>

  <item name="colorPrimaryDark">@color/primary_dark</item>

  <item name="colorAccent">@color/accent</item>

</style>



-

Activity 도 ActionBarActivity 를 상속받도록 하자.

ActionBarActivity 는 FrgmentActivity 를 상속한 녀석이다.


public class BaseActionBarActivity extends ActionBarActivity {

    // Implementation

}



-

위의 3가지 세팅으로 이미 기본 Material Support Library 사용 준비가 끝났다.



-

@Activity

getActionBar() -> getSupportActionBar()



-

@xml

xmlns:app="http://schemas.android.com/apk/res-auto"


android:showAsAction -> app:showAsAction 



-

PreferenceActivity -> ActionBarActivity + PreferenceFragment


여기에는 pit fall(단점) 이 있는데, PreferenceFragment 는 Fragment 를 상속한 녀석이기 떄문에 ( not support fragment )

getSupportFragmentManager 대신 getFragmentManager 를 사용해야 한다.


그래서 Gingerbread 를 support 한다면 custom layout 을 쓰거나, 분기를 타거나 등을 해야 한다.

( Gingerbread 에는 Fragment 개념이 없어서 getFragmentManager 자체가 없다. )



-

기존에 Drawer 를 사용했다면, Activity 에 NoTitleBar 를 설정하고, DrawerLayout 과 Toolbar 를 사용하자

-> Material Design Check List 에 보면 DrawerLayout 는 StatusBar 밑에 반투명으로 그려져야 한다.



@style

<style name="AppTheme.NoTitleBar">

  <item name="windowActionBar">false</item>

  <item name="android:windowNoTitle">true</item>

</style>


@drawerlayout 안에 toolbar add & drawerlayout  을 root 로 사용하자.

<android.support.v7.widget.Toolbar

    android:id="@+id/toolbar"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:background="?attr/colorPrimary"

    android:minHeight="?attr/actionBarSize"

    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />



-

Drawer 의 top 부분을 semi-transparent 하게 만들려면,

DrawerLayout 의 xml 에 fitsSystemWindows 를 true 로 준다. ( 코드로 줘도 된다, api level 14 )

fitsSystemWindows 를 true 로 줬다는 것은 statusbar 까지 view 영역을 확장한다는 의미이다.


@v-21 app theme 에 아래 코드를 추가 ( android 5.0 이상에서만 가능 )

<item name="android:windowDrawsSystemBarBackgrounds">true</item> <!— 상태바까지 그릴 수 있도록 허용 —>

<item name="android:statusBarColor">@color/desired_color</item>




반응형

댓글