cha*_*rma 5 android navigationcontroller android-fragments
我正在使用导航控件(Android体系结构)。我使用了一些演示并创建了导航架构。但是问题是,片段每次都会被召回,就像:从任何片段返回时都替换片段。因此,如何停止此操作,以及如何设置类似“添加片段”而不是“替换片段”的行为。
我在网络上发现了这个问题,但是没有人给我关于如何在导航控件上添加/替换片段的想法。我尝试使用片段ID来获取添加片段的方法,但未成功。
<?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/nav_graph"
app:startDestination="@id/questionanswer">
<fragment
android:id="@+id/questionanswer"
android:name="com.softtech360.totalservey.fragment.QuestionAnswer"
android:label="fragment_first"
tools:layout="@layout/questionanswer" >
<action
android:id="@+id/action_questionanswer_to_questionanswer"
app:destination="@id/questionanswer"
/>
</fragment>
</navigation>
Run Code Online (Sandbox Code Playgroud)
val navController = Navigation.findNavController(activity!!,R.id.navhost_fragment)
navController.navigate(R.id.questionanswer)
// using this i swap the fragment on host fragment.
Run Code Online (Sandbox Code Playgroud)
尝试这个:
<action
android:id="@+id/action_questionanswer_to_questionanswer"
app:popUpTo="@+id/questionanswer"/>
Run Code Online (Sandbox Code Playgroud)
代替
<action
android:id="@+id/action_questionanswer_to_questionanswer"
app:destination="@id/questionanswer"/>
Run Code Online (Sandbox Code Playgroud)
进而:
navController.navigate(R.id.action_questionanswer_to_questionanswer)
Run Code Online (Sandbox Code Playgroud)
在这里找到了这个
| 归档时间: |
|
| 查看次数: |
276 次 |
| 最近记录: |