Commit ba02b6a8 authored by Timothé KOBAK's avatar Timothé KOBAK

Bonus Button : Settings Exit added

parent d8f27b64
package com.example.elbuenopeso
import AdAdapter
import android.os.Bundle
import com.google.android.material.bottomnavigation.BottomNavigationView
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.example.elbuenopeso.databinding.ActivityMainBinding
import com.example.elbuenopeso.models.AdModel
import com.google.android.material.bottomnavigation.BottomNavigationView
class MainActivity : AppCompatActivity() {
......@@ -24,6 +25,7 @@ class MainActivity : AppCompatActivity() {
val navView: BottomNavigationView = binding.navView
val navController = findNavController(R.id.nav_host_fragment_activity_main)
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
val appBarConfiguration = AppBarConfiguration(
......@@ -34,6 +36,28 @@ class MainActivity : AppCompatActivity() {
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.about -> {
Toast.makeText(this, "About Selected", Toast.LENGTH_SHORT).show()
return true
}
R.id.settings -> {
Toast.makeText(this, "Settings Selected", Toast.LENGTH_SHORT).show()
return true
}
R.id.exit -> {
Toast.makeText(this, "Exit Selected", Toast.LENGTH_SHORT).show()
return true
}
else -> return super.onOptionsItemSelected(item)
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/overflowMenu"
android:icon="@drawable/ic_home_black_24dp"
android:title=""
app:showAsAction="always">
<menu>
<item
android:id="@+id/settings"
android:icon="@drawable/ic_home_black_24dp"
android:title="SETTINGS"
app:showAsAction="never" />
<item
android:id="@+id/about"
android:icon="@drawable/ic_home_black_24dp"
android:title="ABOUT"
app:showAsAction="never" />
<item
android:id="@+id/exit"
android:icon="@drawable/ic_home_black_24dp"
android:title="EXIT"
app:showAsAction="never" />
</menu>
</item>
</menu>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment