๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
IT-Engineering/Android

์•ˆ๋“œ๋กœ์ด๋“œ ์ŠคํŠœ๋””์˜ค Material Design ์ ์šฉํ•˜๊ธฐ

by ๐Ÿงž‍โ™‚๏ธ 2020. 3. 22.
๋ฐ˜์‘ํ˜•

material.io ๋ฅผ ๋“ค์–ด๊ฐ€๋ณด๋ฉด ์•ˆ๋“œ๋กœ์ด๋“œ์˜ ์•„๋ฆ„๋‹ต๊ณ  ์ •๊ฐˆํ•œ ๋””์ž์ธ, ๊ทธ๋ฆฌ๊ณ  ๊ทธ ์ฒ ํ•™์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

์šฐ์„  ์‰ฝ๊ฒŒ ํ”„๋กœ์ ํŠธ์— Material Design์„ ์ ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์†Œ๊ฐœํ•œ๋‹ค.

ํ”„๋กœ์ ํŠธ AndroidX migrate๋ฅผ ํ–ˆ๋‹ค๋Š” ๊ฐ€์ •ํ•˜์—, ํ˜น์€ ์•ˆ๋“œ๋กœ์ด๋“œ ์ŠคํŠœ๋””์˜ค ์ตœ์‹ ๋ฒ„์ „์„ ์‚ฌ์šฉํ–ˆ๋‹ค๋Š” ๊ฐ€์ •ํ•˜์—

(ํ•„์ž๋Š” Android Studio 3.6.1 ๋ฒ„์ „์„ ์‚ฌ์šฉ ์ค‘)

๋จผ์ € ์ขŒ์ธก ํ”„๋กœ์ ํŠธ ํŠธ๋ฆฌ์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ถ€๋ถ„์„ ํด๋ฆญํ•œ๋‹ค.

build.gradle(Module:app)์„ ํด๋ฆญํ•˜์ž.

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'    
}

์œ„์™€ ๊ฐ™์€ ๋ถ€๋ถ„์—์„œ

androidx.appcompat:appcompat:1.1.0์˜ ๋ฒ„์ „ ์ˆซ์ž์— ๋งž๊ฒŒ ์•„๋ž˜์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.

implementation 'com.google.android.material:material:1.1.0'

๊ทธ๋Ÿผ ์•„๋ž˜์™€ ๊ฐ™์€ ๋ชจ์Šต์ด ๋  ๊ฒƒ์ด๋‹ค.

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

์ถ”๊ฐ€๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ๋‹ค๋ฉด, ์•„๋ž˜์˜ Sync Now ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ๋™๊ธฐํ™”๋ฅผ ์‹œ์ผœ์ฃผ์ž.

Gradle์˜ Sync๋ฅผ ์‹œ์ผœ์ฃผ๋„๋ก ํ•˜์ž.

์ด์ œ ํ…Œ๋งˆ๋ฅผ Material Theme๋กœ ์ ์šฉํ•ด๋ณด์ž.

AndroidX๋กœ migrateํ•ด์„œ Material ํ…Œ๋งˆ๋ฅผ ์ „์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฒฝ์šฐ

AndroidManifest.xmlํŒŒ์ผ์—์„œ Application์— ์ดˆ๊ธฐ๊ฐ’์œผ๋กœ ์ ์šฉํ•˜๊ณ  ์žˆ๋Š” AppTheme๋ฅผ

styles.xml์„ ํ†ตํ•ด parent="Theme.AppCompat.Light.DarkActionBar"๋ฅผ

parent="Theme.MaterialComponents.Light.DarkActionBar"

์œผ๋กœ ์ ์šฉํ•˜๋ฉด, ์ดํ›„์— ์‚ฌ์šฉ๋˜๋Š” View๋“ค, ์˜ˆ๋ฅผ ๋“ค์–ด Button๊ณผ ๊ฐ™์€ ๊ฐ์ฒด๋“ค์„ ์ผ์ผ์ด

<com.google.android.material.button.MaterialButton>์ด๋Ÿฐ ํ˜•ํƒœ ๋Œ€์‹ ์—

<Button>์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค.

์ ์šฉํ•œ ๋’ค ๋ชจ์Šต์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€๋ฐ, ์–ด๋–ค ํŠน๋ณ„ํ•œ ํŠœ๋„ ์ถ”๊ฐ€ํ•˜๊ณ  ์ ์šฉํ•˜์ง€ ์•Š์•˜๊ธฐ์— ๊ทธ๋Œ€๋กœ ๋ณด์ผ ๊ฒƒ์ด๋‹ค.

Material Design์ด ์ ์šฉ๋˜์—ˆ์œผ๋‚˜ ์•„์ง์€ ์ฐจ์ด๋ฅผ ๋Š๋‚„ ์ˆ˜๊ฐ€ ์—†๋‹ค.

์–ด์จŒ๋“  ์šฐ์„  1์ฐจ์ ์œผ๋กœ Material Design์˜ ์ปดํฌ๋„ŒํŠธ๋“ค์„ ์‚ฌ์šฉํ•  ์ค€๋น„๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ๋‹ค.

์ด์ œ activity_main.xml๋กœ ๋“ค์–ด๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด TextView๋ฅผ Button์œผ๋กœ๋งŒ ๋ณ€๊ฒฝํ•˜์—ฌ ๋‹ค์‹œ ์‹คํ–‰์‹œ์ผœ๋ณด์ž.

activity_main.xml
<?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">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

์ด๋žฌ๋˜ ๋ฒ„ํŠผ์ด

Material Design ์ ์šฉํ•˜๊ธฐ ์ „ ๋ฒ„ํŠผ

๋‹ค์Œ์˜ ๋ชจ์Šต์œผ๋กœ ์˜ˆ์˜๊ฒŒ ๋ณ€๊ฒฝ๋˜์—ˆ๋‹ค!

Material Design์ด ์ ์šฉ๋œ ๋ฒ„ํŠผ ๋ชจ์Šต

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€