Created
March 2, 2020 18:50
-
-
Save abdulazizahwan/64641672171234c0d1e4de5d6b80aadc to your computer and use it in GitHub Desktop.
MainActivity for tutorial https://youtu.be/JTTs4Xbthmc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.bottomnavigationbar | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import android.view.View | |
import androidx.core.content.ContextCompat | |
import com.fxn.ariana.ArianaBackgroundListener | |
import kotlinx.android.synthetic.main.activity_main.* | |
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
menu_bottom.setOnItemSelectedListener { id -> | |
when (id) { | |
R.id.home -> viewpager.currentItem = 0 | |
R.id.like -> viewpager.currentItem = 1 | |
R.id.search -> viewpager.currentItem = 2 | |
R.id.profile -> viewpager.currentItem = 3 | |
} | |
} | |
viewpager.setOnTouchListener(View.OnTouchListener { v, event -> true }) | |
viewpager.adapter = ViewPagerAdapter(supportFragmentManager).apply { | |
list = ArrayList<String>().apply { | |
add("Home") | |
add("Like") | |
add("Search") | |
add("Profile") | |
} | |
} | |
viewpager.addOnPageChangeListener( | |
ArianaBackgroundListener( | |
getColors(), | |
img1, | |
viewpager | |
) | |
) | |
} | |
private fun getColors(): IntArray { | |
return intArrayOf( | |
ContextCompat.getColor(this, R.color.home), | |
ContextCompat.getColor(this, R.color.like), | |
ContextCompat.getColor(this, R.color.search), | |
ContextCompat.getColor(this, R.color.profile), | |
ContextCompat.getColor(this, R.color.home) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment