[ ์•ˆ๋“œ๋กœ์ด๋“œ - ์ฝ”ํ‹€๋ฆฐ ] Dialog์— RatingBar ์ถ”๊ฐ€ํ•˜๊ธฐ

2023. 1. 28. 18:43ใ†Android

๐Ÿ˜…  RatingBar ๋งŒ๋“ค๋ฉด์„œ ๊ฒช์€ ๋ฌธ์ œ์ ์„ ์ ์–ด๋ณด๊ฒ ๋‹ค 

์ด๋ฒˆ์— ์ปค์Šคํ…€ ๋‹ค์ด์–ผ๋กœ๊ทธ์— ratingbar๋ฅผ ์ฒ˜์Œ ์จ๋ณด๊ฒŒ ๋ฌ๋Š”๋ฐ ์ƒ๊ฐ๋ณด๋‹ค ์˜ค๋ž˜ ๊ฑธ๋ ค์„œ ๊ธฐ๋ก์„ ๋‚จ๊ธด๋‹ค

 

1. ํฌ๊ธฐ ์กฐ์ ˆ ๋ฌธ์ œ 

2. ์ƒ‰ ์กฐ์ ˆ ๋ฐ ๋ฐฐ๊ฒฝ ์ƒ‰ ์กฐ์ ˆ

3. ํด๋ฆญ ์ด๋ฒคํŠธ ์ž‘๋™ ์•ˆ๋จ

4. ์ƒ‰ ์ž”์ƒ ๊ฐ™์€ ๋ฐฐ๊ฒฝ์ด ๋‚จ์Œ

 

๋ชจ๋“  ๋ฌธ์ œ์ ์„ ํ•ด๊ฒฐํ•˜๊ณ  ๋งŒ๋“ค์–ด์ง„ ratingbar ์ด๋‹ค 

<RatingBar
    android:id="@+id/dialog_rtb"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:stepSize="1.0"
    android:isIndicator="false"
    android:secondaryProgressTint="@android:color/transparent"
    android:progressBackgroundTint="@color/black"
    android:progressTint="#F2594B"
    android:layout_marginTop="25dp"
    android:layout_gravity="center"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView2"
    style="@style/Widget.AppCompat.RatingBar.Indicator"/>

 

1๋ฒˆ ๋ฌธ์ œ์ ์€ ์•ˆ๋“œ๋กœ์ด๋“œ style์—์„œ ์œ„์ ฏ ํฌ๊ธฐ๋ฅผ 3๊ฐ€์ง€๋กœ ์กฐ์ ˆํ•  ์ˆ˜ ์žˆ๋‹ค ๊ทธ ์ด์™ธ์˜ ์‚ฌ์ด์ฆˆ๋Š” ์ปค์Šคํ…€์„ ํ†ตํ•ด ๋งŒ๋“ค์–ด์•ผ๋œ๋‹ค 

 

2๋ฒˆ ๋ฌธ์ œ์ ์€ progressTint์—์„œ ์ƒ‰์„ ๋ณ€๊ฒฝํ•ด์ฃผ๋Š” ๊ฒƒ์œผ๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค 

 

3๋ฒˆ ํด๋ฆญ ์ด๋ฒคํŠธ๋Š” style์„ ์ ์šฉํ•˜์ง€ ์•Š์€ ๊ธฐ๋ณธ ๋ฒ„์ „์€ ๋‹ค๋ฅธ ์„ค์ • ์—†์ด ์กฐ์ ˆ์ด ๊ฐ€๋Šฅํ–ˆ์ง€๋งŒ 1๋ฒˆ ์‚ฌ์ด์ฆˆ ์กฐ์ ˆ์„ ํ•˜๊ฒŒ๋˜๋ฉด ์ด๋ฒคํŠธ๊ฐ€ ์ ์šฉ์ด ๋˜์ง€ ์•Š๋Š”๋‹ค ์ด๋Ÿด ๋•Œ๋Š” isIndicator๋กœ ์‚ฌ์šฉ์ž๊ฐ€ ์กฐ์ ˆ์„ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“ค์–ด์ค˜์•ผ๋œ๋‹ค

detailDialog.show()
detailDialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))

val dialog_btn : AppCompatButton = detailDialog.findViewById(R.id.dialog_btn)
val dialog_rtb : RatingBar = detailDialog.findViewById(R.id.dialog_rtb)

dialog_rtb.setOnRatingBarChangeListener { _, fl, _ ->
    dialog_rtb.rating = fl
}

 

4๋ฒˆ ์ž”์ƒ์€ ํ•˜๋‹จ ์‚ฌ์ง„์ฒ˜๋Ÿผ ์™ผ์ชฝ ๋ถ€๋ถ„์— ํŒŒ๋ž€์ƒ‰ ๋ถ€๋ถ„์ด ๋‚˜ํƒ€๋‚œ๋‹ค 20๋ถ„์ •๋„ ๋’ค์ ๊ฑฐ๋ฆฌ๋‹ค ์ €๊ฒŒ ๊ทธ๋ฆผ์ž์•„๋‹ˆ๋ƒ๋Š” ์นœ๊ตฌ์˜ ์กฐ์–ธ์œผ๋กœ stackoverflow๋ฅผ ์ฐพ์•„๋ณด๋‹ˆ ๋ฐ”๋กœ๋‚˜์™€๋ฒ„๋ ธ๋‹ค ^^;;

ํ•˜๋‹จ ๋งํฌ ์ฐธ์กฐ

 

https://stackoverflow.com/questions/46619240/disable-shadow-in-ratingbar