/**
* meow-bottom-navigation
*/
implementation 'com.etebarian:meow-bottom-navigation:1.2.0'
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/nav_host_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/btn_nav"
android:layout_alignParentLeft="true" />

<com.etebarian.meowbottomnavigation.MeowBottomNavigation
android:id="@+id/btn_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:mbn_backgroundBottomColor="@color/color_primary"
app:mbn_circleColor="@color/white"
app:mbn_defaultIconColor="@color/white"
app:mbn_rippleColor="@color/transparent"
app:mbn_selectedIconColor="@color/color_primary" />
</RelativeLayout>
<color name="transparent">#00000000</color>
<color name="color_primary">#1E37DD</color>
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
supportActionBar?.hide()
window.apply {
addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
statusBarColor
= Color.TRANSPARENT
}
val homeFragment = HomeFragment()
val settingFragment = SettingFragment()
val transactionFragment = TransactionFragment()
setFragment(homeFragment)

val btn_nav = findViewById<MeowBottomNavigation>(R.id.btn_nav)

try {
btn_nav.add(MeowBottomNavigation.Model(1, R.drawable.icon_trx))
btn_nav.add(MeowBottomNavigation.Model(2, R.drawable.icon_home))
btn_nav.add(MeowBottomNavigation.Model(3, R.drawable.icon_setting))

btn_nav.setOnClickMenuListener {
when (it.id) {
1 -> setFragment(transactionFragment)
2 -> setFragment(homeFragment)
3 -> setFragment(settingFragment)

else -> " "
}
true
}
btn_nav.show(2)

} catch (e: Exception) {

}

}

fun setFragment(fragment: Fragment) {
supportFragmentManager
.beginTransaction().apply {
replace(R.id.nav_host_fragment_container, fragment, "bottomNavigation")
commit()
}

}

private var doubleBackToExitPressedOnce = false
override fun onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed()
return
}
this.doubleBackToExitPressedOnce = true
this.let { it1 ->
Snackbar.make(
it1.findViewById(android.R.id.content),
getString(R.string.label_close_app),
Snackbar.LENGTH_INDEFINITE
).setDuration(8000).show()
}
Handler().postDelayed(Runnable { doubleBackToExitPressedOnce = false }, 2000)
}
}
<string name="label_close_app">press the back button again to close the app ~</string>

--

--

--

https://www.linkedin.com/in/usman-idzhami-763b47186

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

8 Useful Kotlin Tips For Android Developers

Laptop screen showing code

Add custom live templates in Android Studio

The Importance of Kotlin in Building Modern Android Apps

Exploring RxJava in Android — Operators for Combining Observables

Building Successful Android Games on Google Play

Hacky Fix for Google’s Own Media Player (TalkSPORT & Times Radio — Android)

Getting Frames of Live camera footage as Bitmaps in Android using Camera2 API Kotlin

Does your app speak in tongues?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Usman Idzhami

Usman Idzhami

https://www.linkedin.com/in/usman-idzhami-763b47186

More from Medium

Tower Watcher

Tower Watcher

Issues & Fixes in Nested ExpandableListView

Issues and fixes in Nested ExpandableListView

Android Background Audio Player with Jetpack Media3

iLocker for Android