320x100
[상황]
android Button 의 테두리에 Radius를 줄까한다
다만 xml 을 작성하기 뭐해서 코드로 적용할까 한다
[참고 플랫폼]
더보기
1. Android Studio Bumblebee | 2021.1.1 Patch 2 | Runtime version: 11.0.11
[코드]
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
findViewById<Button>(R.id.btn_v1).background = simpleRadius(getColor(R.color.purple_200), 30F)
findViewById<Button>(R.id.btn_v2).background = simpleRadius(getColor(R.color.purple_500), 50F)
findViewById<Button>(R.id.btn_v3).background = simpleRadius(getColor(R.color.purple_700), 70F)
}
private fun simpleRadius(color: Int, radius: Float): GradientDrawable {
val gradientDrawable = GradientDrawable()
gradientDrawable.setColor(color)
gradientDrawable.cornerRadius = radius
return gradientDrawable
}
}
[코드 : 적용 결과]
320x100
'Android > Kotlin' 카테고리의 다른 글
[Android][Kotlin] Dialog 커스텀 및 스타일 수정 (0) | 2022.10.05 |
---|---|
[Android][Kotlin] 특정 시간 뒤 작업 Handler postDelayed (0) | 2022.10.04 |
[Android][Kotlin] AlertDialog (2) | 2022.10.04 |
[Android][Kotlin] 특정 View를 Bitmap으로 변환 후 이미지로 저장하는 방법 (0) | 2022.09.23 |
[Android][Kotlin] 메서드 파라미터 함수 넣기 : 고차 함수 활용 (0) | 2022.09.20 |