सीकबार एंड्रॉइड कोटलिन

Feb 08 2022
.
  1. ऑनटच, ऑनस्टार्ट और स्टॉप पर सीकबार फंक्शन लिखा जाता है।
  2. एक्सएमएल
  3. <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    
        <SeekBar
            android:id="@+id/seekbar_Default"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.174" />
    
        <SeekBar
            android:id="@+id/seekbar_Discrete"
            style="@style/Widget.AppCompat.SeekBar.Discrete"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:max="10"
            android:progress="0"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.333" />
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    package com.example.myapplication
    
    import androidx.appcompat.app.AppCompatActivity
    import android.os.Bundle
    import android.widget.SeekBar
    import android.widget.Toast
    
    class MainActivity : AppCompatActivity() {
    
        var seekBarNormal: SeekBar? = null
        var seekBarDiscrete: SeekBar? = null
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
            seekBarNormal= findViewById(R.id.seekbar_Default)
            seekBarDiscrete = findViewById(R.id.seekbar_Discrete)
    
            seekBarNormal?.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
                override fun onProgressChanged(seekBar: SeekBar, progress: Int,
                                               fromUser: Boolean) {
                    Toast.makeText(applicationContext, "seekbar progress: $progress", Toast.LENGTH_SHORT).show()
                }
    
                override fun onStartTrackingTouch(seekBar: SeekBar) {
                    Toast.makeText(applicationContext, "seekbar touch started!", Toast.LENGTH_SHORT).show()
                }
    
                override fun onStopTrackingTouch(seekBar: SeekBar) {
                    Toast.makeText(applicationContext, "seekbar touch stopped!", Toast.LENGTH_SHORT).show()
                }
            })
    
            seekBarDiscrete?.setOnSeekBarChangeListener(object :SeekBar.OnSeekBarChangeListener{
                override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                    // TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
                    Toast.makeText(applicationContext, "discrete seekbar progress: $progress", Toast.LENGTH_SHORT).show()
                }
    
                override fun onStartTrackingTouch(seekBar: SeekBar?) {
                    //  TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
                    Toast.makeText(applicationContext, "discrete seekbar touch started!", Toast.LENGTH_SHORT).show()
                }
    
                override fun onStopTrackingTouch(seekBar: SeekBar?) {
                    //  TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
                    Toast.makeText(applicationContext, "discrete seekbar touch stopped", Toast.LENGTH_SHORT).show()
                }
            })
        }
    }