mirror of
https://github.com/Skysamara/android-kotlin-fundamentals-apps.git
synced 2025-12-06 06:16:03 +00:00
Android Kotlin Fundamentals 03.2: Define navigation paths
9. Task: Add an options menu
This commit is contained in:
parent
7e229e5b07
commit
8c386416cf
@ -18,12 +18,11 @@
|
|||||||
|
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.*
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import androidx.databinding.DataBindingUtil
|
import androidx.databinding.DataBindingUtil
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
|
import androidx.navigation.ui.NavigationUI
|
||||||
import com.example.android.navigation.databinding.FragmentTitleBinding
|
import com.example.android.navigation.databinding.FragmentTitleBinding
|
||||||
|
|
||||||
|
|
||||||
@ -46,8 +45,18 @@ class TitleFragment : Fragment() {
|
|||||||
binding.playButton.setOnClickListener { view: View ->
|
binding.playButton.setOnClickListener { view: View ->
|
||||||
view.findNavController().navigate(R.id.action_titleFragment_to_gameFragment)
|
view.findNavController().navigate(R.id.action_titleFragment_to_gameFragment)
|
||||||
}
|
}
|
||||||
|
setHasOptionsMenu(true)
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
|
||||||
|
super.onCreateOptionsMenu(menu, inflater)
|
||||||
|
inflater?.inflate(R.menu.option_menu, menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
||||||
|
return NavigationUI.onNavDestinationSelected(item!!, view!!.findNavController())
|
||||||
|
|| super.onOptionsItemSelected(item)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/aboutFragment"
|
||||||
|
android:title="@string/about" />
|
||||||
|
</menu>
|
||||||
@ -52,4 +52,9 @@
|
|||||||
app:popUpTo="@id/titleFragment"
|
app:popUpTo="@id/titleFragment"
|
||||||
app:popUpToInclusive="false" />
|
app:popUpToInclusive="false" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/aboutFragment"
|
||||||
|
android:name="com.example.android.navigation.AboutFragment"
|
||||||
|
android:label="fragment_about"
|
||||||
|
tools:layout="@layout/fragment_about" />
|
||||||
</navigation>
|
</navigation>
|
||||||
Loading…
x
Reference in New Issue
Block a user