Android Application
Kotlin 고급 위젯 - 기 타: 프로그레스바(ProgressBar)
작성자 임베디드코리아
작성일23-09-24 01:37
조회1,521회
댓글0건
------------------------------------------------------------------------------------
activity_main.xml
-------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ProgressBar
android:id="@+id/pb1"
style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="#FF00D5"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginTop="100dp"/>
<ProgressBar
android:id="@+id/pb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="#00E1FF"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginTop="50dp" />
<ProgressBar
android:id="@+id/pb3"
style="@android:style/Widget.DeviceDefault.ProgressBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="#FFB300"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginTop="50dp" />
</LinearLayout>
<ProgressBar
android:id="@+id/pb4"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleY="5"
android:progressBackgroundTint="#00EAFF"
android:progressTint="#3949AB"
android:layout_marginTop="50dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5만큼 증가"
android:layout_marginLeft="10dp"
android:layout_marginTop="50dp" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5만큼 증가"
android:layout_marginLeft="20dp"
android:layout_marginTop="50dp"/>
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="50으로 설정"
android:layout_marginLeft="20dp"
android:layout_marginTop="50dp"/>
</LinearLayout>
<ProgressBar
android:id="@+id/progressbar"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="48dp"
android:indeterminate="false"
android:max="100"
android:progressBackgroundTint="#D81B60"
android:progressTint="#4166ED" />
</LinearLayout>
------------------------------------------------------------------------------------
MainActivity.kt
-------------------------------------------------------------------------------------
class MainActivity : AppCompatActivity() {
private lateinit var btn: Button
private lateinit var btn2: Button
private lateinit var btn3: Button
private lateinit var pb4: ProgressBar
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btn= findViewById(R.id.btn)
btn2= findViewById(R.id.btn2)
btn3= findViewById(R.id.btn3)
pb4= findViewById(R.id.pb4)
// 별다른 리스너가 존재하지 않는다.
btn.setOnClickListener { view ->
pb4.incrementProgressBy(5)
}
btn2.setOnClickListener { view ->
pb4.incrementProgressBy(-5)
}
btn3.setOnClickListener { view ->
pb4.progress = 50
}
}
}