Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 버전일치
- kotlin
- degit
- 함수
- 스타일보험
- FIle
- Android
- 오버라이드
- 답글
- parcel
- 코틀린
- git
- 안드로이드
- 스프링
- 왕초보
- 시큐어코딩
- 상속
- sub query
- 쿠키
- React
- SQL
- 숫자
- java
- snowpack
- 미니게임
- Spring
- 게시판
- Spinner
- webpack
- java#왕초보
Archives
- Today
- Total
YSHUSH
Seek bar 본문
seek bar를 조작하면 해당하는 숫자가
텍스트뷰에 나오도록 해보자
1. activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.41"
android:id="@+id/textView"/>
<SeekBar
android:layout_width="459dp"
android:layout_height="43dp"
android:id="@+id/seekBar"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"/>
</androidx.constraintlayout.widget.ConstraintLayout>
2. MainActivity.kt
class MainActivity : AppCompatActivity() {
@RequiresApi(Build.VERSION_CODES.O)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val seekBar = findViewById<SeekBar>(R.id.seekBar)
val textView = findViewById<TextView>(R.id.textView)
seekBar.max = 10
seekBar.min = 2
seekBar.setOnSeekBarChangeListener(object :SeekBar.OnSeekBarChangeListener{
override fun onProgressChanged(p0: SeekBar?, progress: Int, p2: Boolean) {
textView.text = "$progress"
}
override fun onStartTrackingTouch(p0: SeekBar?) {
}
override fun onStopTrackingTouch(p0: SeekBar?) {
}
})
}
}
seek bar의 최댓값과 최솟값을 지정해 줄 수 있다.
seekBar.max = 10
seekBar.min = 2
'Coding > Android(kotlin)' 카테고리의 다른 글
Counter(숫자 세기 미니 프로그램) (0) | 2022.02.08 |
---|---|
Rating bar (0) | 2022.02.08 |
Navigation menu (0) | 2022.02.08 |
Fragment (0) | 2022.02.08 |
Spinner2 (0) | 2022.02.08 |