mirror of
https://github.com/Skysamara/android-kotlin-fundamentals-apps.git
synced 2025-12-06 06:16:03 +00:00
Task: Add fragments to the navigation graph
This commit is contained in:
parent
436fff9aa9
commit
8d1891dc0d
@ -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"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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>
|
||||||
|
|
||||||
|
|||||||
@ -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>
|
||||||
@ -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'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user