이 글은 유데미 강의 Android 12 및 Kotlin 개발 완전 정복을 참고하여 작성하였습니다.
작성자 : 조성현
개발환경은 mac, Android Studio입니다.
강의 123~125에 대한 리뷰 형식의 글입니다.
123 색상 선택 하기
class DrawingView
newColor 로 색상을 받아 Color class 의 parseColor 에 넣어 준다 .-> 색상 코드를 적용하는 메서드이다.
fun setColor(newColor: String) {
color = Color.parseColor(newColor)
mDrawPaint?.color = color
}
색상을 그려주는 paint 클라스를 data type 으로 가는 mDrawPaint 이다.
private var mDrawPaint: Paint? = null
class filed 에 선언된 멤버 변수
private var color = Color.BLACK
색상 선택 ui 이다
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="2dp"
android:background="@color/black"
android:contentDescription="image"
android:onClick="paintClicked"
android:src="@drawable/pallet_normal"
android:tag="@color/black" />
fun paintClicked(view: View) {
if (view !== mImageButtonCurrentPaint) {
val imageButton = view as ImageButton
val colorTag = imageButton.tag.toString()
drawingView?.setColor(colorTag)
imageButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.pallet_pressed))
mImageButtonCurrentPaint?.setImageDrawable(
ContextCompat.getDrawable(
this,
R.drawable.pallet_normal
)
)
//Current view is updated with selected view in the form of ImageButton.
mImageButtonCurrentPaint = view
}
}
<LinearLayout
android:id="@+id/ll_action_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<!--TODO(Step 1 - We have added an image button for selecting the image from your phone.)-->
<ImageButton
android:id="@+id/ib_gallery"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:contentDescription="image"
android:scaleType="fitXY"
android:src="@drawable/ic_gallery" />
<ImageButton
android:id="@+id/ib_brush"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:contentDescription="image"
android:scaleType="fitXY"
android:src="@drawable/ic_brush" />
</LinearLayout>
'GDSC HUFS 4기 > Kotlin Team #7' 카테고리의 다른 글
[7팀] 드로잉 앱 안드로이드 12 part 8 (0) | 2022.11.21 |
---|---|
[7팀] 드로잉 앱 안드로이드 12 part 3 (0) | 2022.11.16 |
[7팀] 드로잉 앱 안드로이드 12 part 2 (0) | 2022.11.14 |
[7팀] 퀴즈 앱 안드로이드 12 part 4 (0) | 2022.11.07 |
[7팀] 퀴즈 앱 안드로이드 12 part 3 (0) | 2022.11.07 |