FragmentContainerView added.

This commit is contained in:
Stefan 2021-06-08 15:05:40 +02:00
parent 90b92cea21
commit 97bf93d755
4 changed files with 19 additions and 12 deletions

View File

@ -1,8 +1,8 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt' apply plugin: "kotlin-kapt"
apply plugin: 'androidx.navigation.safeargs.kotlin' apply plugin: "androidx.navigation.safeargs.kotlin"
apply plugin: 'kotlin-parcelize' apply plugin: "kotlin-parcelize"
android { android {
compileSdkVersion 30 compileSdkVersion 30
@ -42,9 +42,8 @@ android {
dependencies { dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"]) implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.0" implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
@ -67,7 +66,7 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
// Kotlin components // Kotlin components
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3" api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0-native-mt"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3" api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0-native-mt"
} }

View File

@ -2,20 +2,28 @@ package com.example.todoapp
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import androidx.navigation.NavController
import androidx.navigation.findNavController import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupActionBarWithNavController import androidx.navigation.ui.setupActionBarWithNavController
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
private lateinit var navController: NavController
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
setupActionBarWithNavController(findNavController(R.id.navHostFragment)) val navHostFragment = supportFragmentManager
.findFragmentById(R.id.navHostFragment) as NavHostFragment
navController = navHostFragment.navController
setupActionBarWithNavController(navController)
} }
override fun onSupportNavigateUp(): Boolean { override fun onSupportNavigateUp(): Boolean {
val navController = findNavController(R.id.navHostFragment)
return navController.navigateUp() || super.onSupportNavigateUp() return navController.navigateUp() || super.onSupportNavigateUp()
} }
} }

View File

@ -6,7 +6,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".MainActivity">
<fragment <androidx.fragment.app.FragmentContainerView
android:id="@+id/navHostFragment" android:id="@+id/navHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment" android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp" android:layout_width="0dp"

View File

@ -8,7 +8,7 @@ buildscript {
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.2.1' classpath 'com.android.tools.build:gradle:4.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files