Hey hello world , welcome to my blog, for over a couple months now my programming language of choice has been Kotlin for many reasons. One off the main reasons is due to the ease in which many of androids more powerful features can be implemented with relatively few lines of code. In this article I will look at how to implement a text Witcher wake very few lines of kotlin code.
[1] To Get started what you need is to add the Textswitcher to the layout file
[2] Then create a list that contains whatever you will need to display in the Textswitcher
[1] To Get started what you need is to add the Textswitcher to the layout file
[2] Then create a list that contains whatever you will need to display in the Textswitcher
var list = listOf("one","two","three","four","five","six","seven")
[3] Utilise the .setFactory method to use the textswitcher,
this allows you to set exactly how the text will be viewed and displayed
tswitch.setFactory { val textView = TextView(this@MainActivity) textView.gravity = Gravity.TOP or Gravity.CENTER_HORIZONTAL textView.textSize = 32f textView.setTextColor(Color.BLUE) textView }[4] I normally create a button to call stuff from the list to be displayed,please bear in mind you will need a if statment to rectet the list and to set the difult value,i was too lazy to set one origanally
but.setOnClickListener { x++ tswitch.setText(list[x].toString()) }
Comments
Post a Comment