├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable │ │ │ │ ├── ic_home_black_24dp.xml │ │ │ │ ├── ic_dashboard_black_24dp.xml │ │ │ │ ├── ic_notifications_black_24dp.xml │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── menu │ │ │ │ └── navigation.xml │ │ │ ├── navigation │ │ │ │ ├── nav_graph_home.xml │ │ │ │ └── nav_graph.xml │ │ │ ├── layout │ │ │ │ ├── fragment_dashboard.xml │ │ │ │ ├── fragment_detail.xml │ │ │ │ ├── fragment_home_container.xml │ │ │ │ ├── fragment_notifications.xml │ │ │ │ ├── activity_main.xml │ │ │ │ └── fragment_home.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── star_zero │ │ │ │ └── navigation_keep_fragment_sample │ │ │ │ ├── DetailFragment.kt │ │ │ │ ├── HomeContainerFragment.kt │ │ │ │ ├── NotificationsFragment.kt │ │ │ │ ├── HomeFragment.kt │ │ │ │ ├── MainActivity.kt │ │ │ │ ├── DashboardAdapter.kt │ │ │ │ ├── DashboardFragment.kt │ │ │ │ └── navigation │ │ │ │ └── KeepStateNavigator.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── star_zero │ │ │ └── navigation_keep_fragment_sample │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── star_zero │ │ └── navigation_keep_fragment_sample │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── art └── navigation.png ├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── README.md ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /art/navigation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-ZERO/navigation-keep-fragment-sample/HEAD/art/navigation.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-ZERO/navigation-keep-fragment-sample/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-ZERO/navigation-keep-fragment-sample/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-ZERO/navigation-keep-fragment-sample/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-ZERO/navigation-keep-fragment-sample/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-ZERO/navigation-keep-fragment-sample/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-ZERO/navigation-keep-fragment-sample/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-ZERO/navigation-keep-fragment-sample/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-ZERO/navigation-keep-fragment-sample/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-ZERO/navigation-keep-fragment-sample/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-ZERO/navigation-keep-fragment-sample/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/STAR-ZERO/navigation-keep-fragment-sample/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | :bangbang: **This repository is just sample** :bangbang: 2 | :bangbang: **This sample does not fix all issues** :bangbang: 3 | 4 | # Navigation + Keep State Fragment 5 | 6 | ![Navigation](art/navigation.png "Navigation") -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Jun 15 08:28:19 JST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Navigation Sample 3 | Home 4 | Dashboard 5 | Notifications 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_home_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_dashboard_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/test/java/com/star_zero/navigation_keep_fragment_sample/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.star_zero.navigation_keep_fragment_sample 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_notifications_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/menu/navigation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 13 | 14 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/navigation/nav_graph_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 14 | 15 | 19 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/star_zero/navigation_keep_fragment_sample/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.star_zero.navigation_keep_fragment_sample 2 | 3 | import androidx.test.InstrumentationRegistry 4 | import androidx.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.star_zero.navigation_keep_fragment_sample", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # Kotlin code style for this project: "official" or "obsolete": 15 | kotlin.code.style=official 16 | android.useAndroidX=true 17 | android.enableJetifier=true 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/star_zero/navigation_keep_fragment_sample/DetailFragment.kt: -------------------------------------------------------------------------------- 1 | package com.star_zero.navigation_keep_fragment_sample 2 | 3 | import android.os.Bundle 4 | import android.util.Log 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import androidx.fragment.app.Fragment 9 | import com.star_zero.navigation_keep_fragment_sample.databinding.FragmentDetailBinding 10 | 11 | class DetailFragment : Fragment() { 12 | 13 | private lateinit var binding: FragmentDetailBinding 14 | 15 | override fun onCreate(savedInstanceState: Bundle?) { 16 | super.onCreate(savedInstanceState) 17 | Log.d("DetailFragment", "onCreate") 18 | } 19 | 20 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 21 | binding = FragmentDetailBinding.inflate(inflater, container, false) 22 | return binding.root 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_dashboard.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/star_zero/navigation_keep_fragment_sample/HomeContainerFragment.kt: -------------------------------------------------------------------------------- 1 | package com.star_zero.navigation_keep_fragment_sample 2 | 3 | import android.os.Bundle 4 | import android.util.Log 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import androidx.fragment.app.Fragment 9 | import com.star_zero.navigation_keep_fragment_sample.databinding.FragmentHomeContainerBinding 10 | 11 | class HomeContainerFragment : Fragment() { 12 | 13 | private lateinit var binding: FragmentHomeContainerBinding 14 | 15 | override fun onCreate(savedInstanceState: Bundle?) { 16 | super.onCreate(savedInstanceState) 17 | Log.d("HomeContainerFragment", "onCreate") 18 | } 19 | 20 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 21 | binding = FragmentHomeContainerBinding.inflate(inflater, container, false) 22 | return binding.root 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/star_zero/navigation_keep_fragment_sample/NotificationsFragment.kt: -------------------------------------------------------------------------------- 1 | package com.star_zero.navigation_keep_fragment_sample 2 | 3 | import android.os.Bundle 4 | import android.util.Log 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import androidx.fragment.app.Fragment 9 | import com.star_zero.navigation_keep_fragment_sample.databinding.FragmentNotificationsBinding 10 | 11 | class NotificationsFragment : Fragment() { 12 | 13 | private lateinit var binding: FragmentNotificationsBinding 14 | 15 | override fun onCreate(savedInstanceState: Bundle?) { 16 | super.onCreate(savedInstanceState) 17 | Log.d("NotificationsFragment", "onCreate") 18 | } 19 | 20 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 21 | binding = FragmentNotificationsBinding.inflate(inflater, container, false) 22 | return binding.root 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/navigation/nav_graph.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/star_zero/navigation_keep_fragment_sample/HomeFragment.kt: -------------------------------------------------------------------------------- 1 | package com.star_zero.navigation_keep_fragment_sample 2 | 3 | import android.os.Bundle 4 | import android.util.Log 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import androidx.fragment.app.Fragment 9 | import androidx.navigation.fragment.findNavController 10 | import com.star_zero.navigation_keep_fragment_sample.databinding.FragmentHomeBinding 11 | 12 | class HomeFragment : Fragment() { 13 | 14 | private lateinit var binding: FragmentHomeBinding 15 | 16 | override fun onCreate(savedInstanceState: Bundle?) { 17 | super.onCreate(savedInstanceState) 18 | Log.d("HomeFragment", "onCreate") 19 | } 20 | 21 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 22 | binding = FragmentHomeBinding.inflate(inflater, container, false) 23 | binding.handler = this 24 | return binding.root 25 | } 26 | 27 | fun navigateToDetail(view: View) { 28 | findNavController().navigate(R.id.action_home_to_detail) 29 | } 30 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_home_container.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_notifications.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/star_zero/navigation_keep_fragment_sample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.star_zero.navigation_keep_fragment_sample 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import androidx.databinding.DataBindingUtil 6 | import androidx.navigation.findNavController 7 | import androidx.navigation.plusAssign 8 | import androidx.navigation.ui.setupWithNavController 9 | import com.star_zero.navigation_keep_fragment_sample.databinding.ActivityMainBinding 10 | import com.star_zero.navigation_keep_fragment_sample.navigation.KeepStateNavigator 11 | 12 | class MainActivity : AppCompatActivity() { 13 | 14 | private lateinit var binding: ActivityMainBinding 15 | 16 | override fun onCreate(savedInstanceState: Bundle?) { 17 | super.onCreate(savedInstanceState) 18 | binding = DataBindingUtil.setContentView(this, R.layout.activity_main) 19 | 20 | val navController = findNavController(R.id.nav_host_fragment) 21 | 22 | // get fragment 23 | val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment)!! 24 | 25 | // setup custom navigator 26 | val navigator = KeepStateNavigator(this, navHostFragment.childFragmentManager, R.id.nav_host_fragment) 27 | navController.navigatorProvider += navigator 28 | 29 | // set navigation graph 30 | navController.setGraph(R.navigation.nav_graph) 31 | 32 | binding.bottomNav.setupWithNavController(navController) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/star_zero/navigation_keep_fragment_sample/DashboardAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.star_zero.navigation_keep_fragment_sample 2 | 3 | import android.view.LayoutInflater 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import android.widget.TextView 7 | import androidx.recyclerview.widget.DiffUtil 8 | import androidx.recyclerview.widget.ListAdapter 9 | import androidx.recyclerview.widget.RecyclerView 10 | 11 | class DashboardAdapter: ListAdapter(DIFF_CALLBACK) { 12 | 13 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 14 | val inflater = LayoutInflater.from(parent.context) 15 | val view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false) 16 | return ViewHolder(view) 17 | } 18 | 19 | override fun onBindViewHolder(holder: ViewHolder, position: Int) { 20 | holder.itemView.findViewById(android.R.id.text1).text = getItem(position) 21 | } 22 | 23 | class ViewHolder(view: View): RecyclerView.ViewHolder(view) 24 | 25 | companion object { 26 | private val DIFF_CALLBACK = object: DiffUtil.ItemCallback() { 27 | override fun areItemsTheSame(oldItem: String, newItem: String): Boolean { 28 | return oldItem == newItem 29 | } 30 | 31 | override fun areContentsTheSame(oldItem: String, newItem: String): Boolean { 32 | return oldItem == newItem 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /app/src/main/java/com/star_zero/navigation_keep_fragment_sample/DashboardFragment.kt: -------------------------------------------------------------------------------- 1 | package com.star_zero.navigation_keep_fragment_sample 2 | 3 | import android.os.Bundle 4 | import android.util.Log 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import androidx.fragment.app.Fragment 9 | import androidx.recyclerview.widget.DividerItemDecoration 10 | import androidx.recyclerview.widget.LinearLayoutManager 11 | import com.star_zero.navigation_keep_fragment_sample.databinding.FragmentDashboardBinding 12 | 13 | class DashboardFragment : Fragment() { 14 | 15 | private lateinit var binding: FragmentDashboardBinding 16 | 17 | override fun onCreate(savedInstanceState: Bundle?) { 18 | super.onCreate(savedInstanceState) 19 | Log.d("DashboardFragment", "onCreate") 20 | } 21 | 22 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 23 | binding = FragmentDashboardBinding.inflate(inflater, container, false) 24 | return binding.root 25 | } 26 | 27 | override fun onActivityCreated(savedInstanceState: Bundle?) { 28 | super.onActivityCreated(savedInstanceState) 29 | 30 | val adapter = DashboardAdapter() 31 | binding.recycler.layoutManager = LinearLayoutManager(requireContext()) 32 | binding.recycler.addItemDecoration(DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL)) 33 | binding.recycler.adapter = adapter 34 | 35 | val data = (1..50).map { "Item $it" } 36 | adapter.submitList(data) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'kotlin-kapt' 5 | 6 | android { 7 | compileSdkVersion 28 8 | defaultConfig { 9 | applicationId "com.star_zero.navigation_keep_fragment_sample" 10 | minSdkVersion 21 11 | targetSdkVersion 28 12 | versionCode 1 13 | versionName "1.0" 14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | dataBinding { 23 | enabled true 24 | } 25 | kotlinOptions { 26 | jvmTarget = "1.8" 27 | } 28 | } 29 | 30 | dependencies { 31 | implementation fileTree(dir: 'libs', include: ['*.jar']) 32 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 33 | implementation 'androidx.appcompat:appcompat:1.0.2' 34 | implementation 'com.google.android.material:material:1.1.0-alpha02' 35 | implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3' 36 | implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha06' 37 | testImplementation 'junit:junit:4.12' 38 | androidTestImplementation 'androidx.test:runner:1.1.1' 39 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' 40 | 41 | implementation "androidx.navigation:navigation-fragment-ktx:2.1.0" 42 | implementation "androidx.navigation:navigation-ui-ktx:2.1.0" 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | 22 | 23 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 11 | 12 | 13 | 17 | 18 | 32 | 33 |