반응형
2초만에 BottomSheet 바텀시트 구현하기
전 게시글에 이어, BottomSheet 도 공유합니다.
.kt
package ${PACKAGE_NAME};
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import com.dreamfora.dreamfora.DreamforaApplication.Companion.getPreference
import com.dreamfora.dreamfora.DreamforaApplication.Companion.setPreference
import com.dreamfora.dreamfora.databinding.${NAME}BottomSheetBinding
import com.dreamfora.dreamfora.global.onThrottleClick
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
#parse("File Header.java")
class ${NAME}BottomSheet : BottomSheetDialogFragment() {
private lateinit var binding: ${NAME}BottomSheetBinding
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = ${NAME}BottomSheetBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
interface OnButtonClickListener {
fun onButtonClicked()
}
fun setButtonClickListener(buttonClickListener: OnButtonClickListener) {
this.buttonClickListener = buttonClickListener
}
private var buttonClickListener: OnButtonClickListener? = null
companion object {
private const val bottomSheetName = "${NAME}BottomSheet"
private fun newInstance(buttonClickListener: OnButtonClickListener) = ${NAME}BottomSheet().apply {
setButtonClickListener(buttonClickListener)
}
fun show(fragmentManager: FragmentManager, buttonClickListener: OnButtonClickListener) {
if (fragmentManager.findFragmentByTag(bottomSheetName) != null) { return }
fragmentManager.beginTransaction().add(newInstance(buttonClickListener), bottomSheetName).commitAllowingStateLoss()
}
}
}
.xml
File name
#set( $LAYOUT_FILE = $PACKAGE_NAME.replaceAll("\.", "/").replaceAll("\w+","\.\.").concat("/../res/layout/").concat($NAME.replaceAll("([a-z])([A-Z]+)", "$1_$2").toLowerCase().concat("_bottom_sheet")) )${LAYOUT_FILE}
<?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="wrap_content"
android:paddingTop="40dp"
android:paddingBottom="45dp">
</androidx.constraintlayout.widget.ConstraintLayout>
반응형
'프로그래밍 > App 개발' 카테고리의 다른 글
[Android] GitHub Actions CI/CD (0) | 2023.11.14 |
---|---|
[Android] 버저닝 정책 (1) | 2023.11.03 |
[Android] File Templates (Dialog) (0) | 2023.11.02 |
[Android] letter capitalization + done button (1) | 2023.02.10 |
[Android] 키보드 Done 으로 변경하기 (개행 막기) (0) | 2022.10.06 |