You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.2 KiB
67 lines
2.2 KiB
package com.example.shakecraft
|
|
|
|
import android.os.Build
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import android.os.Bundle
|
|
import androidx.annotation.RequiresApi
|
|
import androidx.core.view.WindowCompat
|
|
import androidx.core.view.WindowInsetsCompat
|
|
import androidx.core.view.WindowInsetsControllerCompat
|
|
import androidx.fragment.app.Fragment
|
|
import com.google.android.material.bottomnavigation.BottomNavigationView
|
|
|
|
class MainActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
|
|
// Function to hide NavigationBar
|
|
@RequiresApi(Build.VERSION_CODES.R)
|
|
private fun hideSystemUI() {
|
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
|
WindowInsetsControllerCompat(window,
|
|
window.decorView.findViewById(android.R.id.content)).let { controller ->
|
|
controller.hide(WindowInsetsCompat.Type.systemBars())
|
|
|
|
// When the screen is swiped up at the bottom
|
|
// of the application, the navigationBar shall
|
|
// appear for some time
|
|
controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
|
}
|
|
}
|
|
|
|
lateinit var bottomNav : BottomNavigationView
|
|
@RequiresApi(Build.VERSION_CODES.R)
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
hideSystemUI()
|
|
setContentView(R.layout.activity_main)
|
|
loadFragment(HomeFragment())
|
|
bottomNav = findViewById(R.id.bottomNav) as BottomNavigationView
|
|
bottomNav.setOnItemSelectedListener {
|
|
when (it.itemId) {
|
|
R.id.home -> {
|
|
loadFragment(HomeFragment())
|
|
true
|
|
}
|
|
R.id.inventory -> {
|
|
loadFragment(InventoryFragment())
|
|
true
|
|
}
|
|
R.id.plus -> {
|
|
loadFragment(CollectFragment())
|
|
true
|
|
}
|
|
else -> false
|
|
}
|
|
}
|
|
}
|
|
private fun loadFragment(fragment: Fragment){
|
|
val transaction = supportFragmentManager.beginTransaction()
|
|
transaction.replace(R.id.container,fragment)
|
|
transaction.commit()
|
|
}
|
|
|
|
|
|
} |