class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
val menuInflater = menuInflater
menuInflater.inflate(R.menu.food_add , menu)
return super.onCreateOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if(item.itemId == R.id.food_add_item){
val action = ListFragmentDirections.actionListFragmentToRecipesFragment()
Navigation.findNavController(this , R.id.fragmentContainerView).navigate(action)
}
return super.onOptionsItemSelected(item)
}
}
I have 2 fragment which are connected to MainActivity with NavHostFragment. I'm trying to make a menu when you open it from right top corner to bring second fragment on the screen but I can't see the bar on the right corner top of the app(also I can't see the top bar at all I couldn't understand?). And since I can't see it, I can't test the menu part at all.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/food_add_item" android:title="Add food"></item>
</menu>
Instead I see this when I run the app
I want to see and control the menu bar and the menu.
You need to check the themes folder. For both day and night xml files. In the theme style, if parent contains something like "NoActionBar" u should change it. Like this code below:
<style name="Base.Theme.App" parent="Theme.AppCompat.Light.NoActionBar">
To something like:
<style name="Base.Theme.App" parent="Theme.AppCompat.Light.DarkActionBar">