Skip to content

5.7. λͺ©ν‘œ

Seulgi Kim edited this page Jan 15, 2021 · 2 revisions

WrittenBy

κ΅¬ν˜„ 방법

λͺ©ν‘œ Main

(1) νƒœκ·Έλ₯Ό 톡해 μƒνƒœλ³„λ‘œ λ‹€λ₯Έ layout을 λ³΄μ—¬μ€Œ

λͺ©ν‘œ Detail

(1) λ””μžμ΄λ„ˆμ˜ μš”κ΅¬μ— 따라 Custom Dialog 생성


κ΅¬ν˜„ μ½”λ“œ

λͺ©ν‘œ Main

(1) νƒœκ·Έλ₯Ό 톡해 μƒνƒœλ³„λ‘œ λ‹€λ₯Έ layout을 λ³΄μ—¬μ€Œ

  • 데이터 바인딩을 μ‚¬μš©ν•΄ visibility 속성 처리

  • fragment_goal.xml

    <data>

        <import type="android.view.View" />
          ...
        <variable
            name="isNotGoalExistThisWeek"
            type="Boolean" />

        <variable
            name="isNotGoalExist"
            type="Boolean" />

        <variable
            name="isGoalExist"
            type="Boolean" />
    </data>
...
        <include
            android:id="@+id/layout_keyword_exist"
            layout="@layout/layout_goal_fragment_keyword_exist"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:visibility="@{isGoalExist ? View.VISIBLE : View.GONE}"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/tv_alert"
            app:temp="@{1}"/>

        <include
            android:id="@+id/layout_keyword_not_this_week"
            layout="@layout/layout_not_keyword_this_week"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:visibility="@{isNotGoalExist ? View.VISIBLE : View.GONE}"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/tv_alert"
            app:temp="@{1}"
            tools:visibility="gone" />

        <include
            android:id="@+id/layout_keyword_not"
            layout="@layout/layout_goal_fragment_not_keyword"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:visibility="@{isNotGoalExistThisWeek ? View.VISIBLE : View.GONE}"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/tv_alert"
            app:temp="@{1}"
            tools:visibility="gone" />

...

λͺ©ν‘œ Detail

(1) λ””μžμ΄λ„ˆμ˜ μš”κ΅¬μ— 따라 Custom Dialog 생성

  • GoalAchieveDialog.kt
class GoalAchieveDialog(context: Context) : Dialog(context) {

    private lateinit var binding: LayoutGoalAchieveDialogBinding

    private var listener: (() -> Unit)? = null
    fun setNegativeButtonClickListener(listener: (() -> Unit)): GoalAchieveDialog {
        this.listener = listener
        return this
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val layoutParams = WindowManager.LayoutParams().apply {
            flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND
            dimAmount = 0.8f
        }

        window?.let {
            it.attributes = layoutParams
            it.setBackgroundDrawableResource(android.R.color.transparent);
        }

        binding= LayoutGoalAchieveDialogBinding.inflate(LayoutInflater.from(context))
        setContentView(binding.root)

        binding.ivCancel.setOnClickListener {
            listener?.invoke()
            dismiss()
        }
    }

}

μ‹€ν–‰ ν™”λ©΄

λͺ©ν‘œ Main λͺ©ν‘œ Detail λͺ©ν‘œ Add
Clone this wiki locally