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 32 33
| class MainActivity : AppCompatActivity(), ViewPager.OnPageChangeListener { override fun onPageScrollStateChanged(p0: Int) { }
override fun onPageScrolled(p0: Int, p1: Float, p2: Int) {
}
override fun onPageSelected(p0: Int) { Toast.makeText(this, p0.toString(), Toast.LENGTH_SHORT).show() }
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) var vp:ViewPager = findViewById(R.id.vp) val pics = arrayOf(R.mipmap.basic, R.mipmap.close, R.mipmap.debug, R.mipmap.edit) val list:MutableList<itemInfo> = mutableListOf() for (i in pics.indices) { list.add(itemInfo((i+1).toString(), pics[i])) } vp.adapter = ImagePagerAdapter(this, list) vp.currentItem = 0 vp.addOnPageChangeListener(this)
var title: PagerTabStrip = findViewById(R.id.title)
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f) title.setTextColor(Color.RED) } }
|