Task: Add fragments to the navigation graph

This commit is contained in:
skysamara 2020-02-19 17:10:08 +03:00
parent 436fff9aa9
commit 8d1891dc0d
5 changed files with 35 additions and 2 deletions

View File

@ -56,4 +56,7 @@ dependencies {
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4' androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation "com.google.android.material:material:1.0.0-rc01" implementation "com.google.android.material:material:1.0.0-rc01"
implementation"android.arch.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "android.arch.navigation:navigation-ui-ktx:$navigationVersion"
} }

View File

@ -23,6 +23,7 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.navigation.findNavController
import com.example.android.navigation.databinding.FragmentTitleBinding import com.example.android.navigation.databinding.FragmentTitleBinding
@ -41,6 +42,10 @@ class TitleFragment : Fragment() {
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View? {
val binding = DataBindingUtil.inflate<FragmentTitleBinding>(inflater, val binding = DataBindingUtil.inflate<FragmentTitleBinding>(inflater,
R.layout.fragment_title,container,false) R.layout.fragment_title,container,false)
binding.playButton.setOnClickListener { view: View ->
view.findNavController().navigate(R.id.action_titleFragment_to_gameFragment)
}
return binding.root return binding.root
} }

View File

@ -23,10 +23,12 @@
android:orientation="vertical"> android:orientation="vertical">
<fragment <fragment
android:id="@+id/titleFragment" android:id="@+id/myNavHostFragment"
android:name="com.example.android.navigation.TitleFragment" android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:navGraph = "@navigation/navigation"
app:defaultNavHost="true"
/> />
</LinearLayout> </LinearLayout>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/navigation"
app:startDestination="@id/titleFragment">
<fragment
android:id="@+id/titleFragment"
android:name="com.example.android.navigation.TitleFragment"
android:label="fragment_title"
tools:layout="@layout/fragment_title" >
<action
android:id="@+id/action_titleFragment_to_gameFragment"
app:destination="@id/gameFragment" />
</fragment>
<fragment
android:id="@+id/gameFragment"
android:name="com.example.android.navigation.GameFragment"
android:label="GameFragment"
tools:layout="@layout/fragment_game"/>
</navigation>

View File

@ -17,6 +17,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext { ext {
navigationVersion = '1.0.0-rc02'
kotlin_version = '1.3.11' kotlin_version = '1.3.11'
archLifecycleVersion = '1.1.1' archLifecycleVersion = '1.1.1'
gradleVersion = '3.3.1' gradleVersion = '3.3.1'