๐ SeSAC์ 'JetPack๊ณผ Kotlin์ ํ์ฉํ Android App ๊ฐ๋ฐ' ๊ฐ์ข๋ฅผ ์ ๋ฆฌํ ๊ธ ์ ๋๋ค.
ํ๋ฉด์ ๋ ์๋ ๋ฏํ ๋ฒํผ์ ์ ๊ณตํ๋ ๋ทฐ
ํํ ์ฝ์ด๋ก FAB
๋ผ๊ณ ๋ถ๋ฅธ๋ค.
๋๋ถ๋ถ ์ฐ์ธก ํ๋จ์ ์์นํ์ง๋ง ์ถ๋ ฅ ์์น๋ ์์๋ก ์ ํ ์ ์๋ค.
์์ ์๋ FloatingActionButton
์ ์ฌ์ฉํ๊ณ , ํ์ฌ๋ ExtendedFloatingActionButton
๋ฅผ ์ฌ์ฉํ๋ค.
FloatingActionButton
์์ ๋ช ๊ฐ์ง ๊ธฐ๋ฅ์ ์ถ๊ฐํ ๊ฒ ๋ฟ์ด๋ค.
FloatingActionButton
์ ๊ฒฝ์ฐ๋ ๊ทธ์ ์ด๋ฏธ์ง๋ฅผ ๋๊ทธ๋ ๋ชจ์์ผ๋ก ์ถ๋ ฅํ๋ ์ ๋์๋๋ฐ,
ExtendedFloatingActionButton
์ ์ด๋ฏธ์ง๋ฟ๋ง ์๋๋ผ ๋ฌธ์์ด๊น์ง๋ ์ถ๋ ฅ์ด ๊ฐ๋ฅํ๋ค.
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="extended FAB"
app:icon="@android:drawable/ic_input_add" />
์ฝ๋์์ ํ์ฅ๋์ด ๋ฌธ์์ด๊น์ง ๋์ค๊ฒ ํ๊ฑฐ๋ ์ถ์๋์ด ์์ด์ฝ๋ง ๋์ค๊ฒ ํ๊ฑฐ๋ ๋ฑ์ ์ฒ๋ฆฌ๊ฐ ๊ฐ๋ฅ
binding.fab.setOnClickListener {
when (binding.fab.isExpanded){
true -> binding.shrink()
false -> binding.fab.extend()
}
}
<?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">
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="extended FAB"
app:icon="@android:drawable/ic_input_add"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
package com.kotdev99.android.c95
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.fab.setOnClickListener {
when (binding.fab.isExtended) {
true -> binding.fab.shrink()
false -> binding.fab.extend()
}
}
}
}