Posts

[ Kotlin ] Text Switcher || Android Studio

Watch Video Tutorial

Step 1 :
  • Create New Project With EmptyActivity
Step 2 :
  • Add TextSwitcher And Button
Step 3 :
  • copy paste this code 
 private val textList = arrayOf("Panda", "Tiger", "Zebra", "Lion", "Deer", "Goat", "Ape", "Monkey", "Human")
    private var index = 0

val textSwitcher = findViewById<TextSwitcher>(R.id.textSwitcher)
        textSwitcher.setFactory {
            val textView = TextView(this@MainActivity)
            textView.gravity = Gravity.TOP or Gravity.CENTER_HORIZONTAL
            textView.textSize = 32f
            textView.setTextColor(Color.RED)
            textView
        }
        textSwitcher.setText(textList[index])

        val `in` = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left)
        textSwitcher.inAnimation = `in`

        val out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right)
        textSwitcher.outAnimation = out

        val button = findViewById<Button>(R.id.button)
        button.setOnClickListener {
            index = if (index + 1 < textList.size) index + 1 else 0
            textSwitcher.setText(textList[index])
        }
Step 4 : 

  • Run Your App

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.