Jetpackのナビゲーション
17876 ワード
Navega Sexes o o dentro de umアプリアンドロイドpode ser feitoデv .Contudo o Jetpack AspresentaアムSafeador que o oナビゲーション構成要素.
ナビゲーションコンポーネントは NAVJOGINGグラフ:um再帰XML XMLモーストラgraficamente todos os caminhos e Destos Da sua navega セグアヌスとしてのパラポンダー来られたar ar a usar oナビゲーション・コンポーネントPrimeiroは、Necess - Leo adicionarとして、NCIASが構築しないということです.グレード
クリックボムoボットは、oを食べます アンドロイドリソースファイル エスコカアムノームパラo エムリソースタイプ
SEAは、Criado - umナビゲーション・グラフVazio Onde Ser -ポーpossを得ます.XML deste arquivo dese se parece com algoはtipoを行う.
Navehost Em - umaの活動を通してのPorso Preisisamos
Voc - de pode ados onos onos endos aoナビゲーショングラフapontando paraフラグメントの存在
エムアムデスティノテトス4アトリウム
IDを定義するIDのIDを実行します
名前は、Caminho da Classe que Pelo C
ラベルノームレッグは、ヴェルDedoをします
レイアウトArquivo XML USADAパラグラフ Examo acima teremos um xml parecido com este :
パラクリアーumアクションBasta Arrastar OマウスデUmデスティニオパラオo outro.UMAアクションTEM os seguintes atributos
IDコンテナーO ID DAアクションパラセールスリファレンス
目的地O IDは、Decinoのonde vde quandoを実行します. アウグゲア・フォーク・エフエヌゥーダ・ドゥ・ファット・ユサンド・ヌム
主な活動.XML
Código Completo
ナビゲーションコンポーネントは
NavHost
: Usコンテナque irは、exbir os目的地dos grNavController
: Ovjeto que gerencia a Navegaの集合NavHost
E orquestra A Trocaデ目的地E interaは、es .dependencies {
def nav_version = "2.3.5"
// Java language implementation
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
// Kotlin
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
// Feature module Support
implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"
// Testing Navigation
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
// Jetpack Compose Integration
implementation "androidx.navigation:navigation-compose:2.4.0-alpha06"
}
参考文献としてのP .<?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"
android:id="@+id/nav_graph">
</navigation>
ヌルホスト
Navehost Em - umaの活動を通してのPorso Preisisamos
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.appcompat.widget.Toolbar
.../>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
<com.google.android.material.bottomnavigation.BottomNavigationView
.../>
</androidx.constraintlayout.widget.ConstraintLayout>
重要事項:android:name
<論説> M・ノ・ミーの概念NavHost
<翻訳>app:navGraph
ノコボ・ナビゲーション・クリアード・パスソapp:defaultNavHost
クアンドtrue
ADAのボットesoの応答に応答します.アドベント
Voc - de pode ados onos onos endos aoナビゲーショングラフapontando paraフラグメントの存在
エムアムデスティノテトス4アトリウム
IDを定義するIDのIDを実行します
名前は、Caminho da Classe que Pelo C
ラベルノームレッグは、ヴェルDedoをします
レイアウトArquivo XML USADAパラグラフ
<?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/fragmentMain">
<fragment
android:id="@+id/fragmentMain"
android:name="com.example.navcomp.FragmentMain"
android:label="fragment_main"
tools:layout="@layout/fragment_main" >
<action
android:id="@+id/action_fragmentMain_to_fragmentSecond"
app:destination="@id/fragmentSecond" />
</fragment>
<fragment
android:id="@+id/fragmentThird"
android:name="com.example.navcomp.FragmentThird"
android:label="fragment_third"
tools:layout="@layout/fragment_third" />
<fragment
android:id="@+id/fragmentSecond"
android:name="com.example.navcomp.FragmentSecond"
android:label="fragment_second"
tools:layout="@layout/fragment_second" >
<action
android:id="@+id/action_fragmentSecond_to_fragmentThird"
app:destination="@id/fragmentThird" />
</fragment>
</navigation>
UKアイテムque vocは、deveターnotadoなしXML acima que n n o oフォアファドs o o oを行動とします.AMAアクションRepresentaは、UMAのconexは、oのl lをGICAの運命の目的地.アクションAusiliam na hora da escritaは、c - dio digo do como eパラシュートで降下します.パラクリアーumアクションBasta Arrastar OマウスデUmデスティニオパラオo outro.UMAアクションTEM os seguintes atributos
IDコンテナーO ID DAアクションパラセールスリファレンス
目的地O IDは、Decinoのonde vde quandoを実行します.
NavController
, Ocjeto que fica dentro de umNavHost
. 3つのformasデacessar umNavController
:Fragment.findNavController()
View.findNavController()
Activity.findNavController(viewId: Int)
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
アゴラ対模範的な完全なda Navega主な活動.XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go To 2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go To 3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<androidx.fragment.app.FragmentContainerView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
</androidx.constraintlayout.widget.ConstraintLayout>
eアクティビティー.KTpackage com.example.navcomp
import android.app.Activity
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment);
val navController = navHostFragment?.findNavController();
var button1 = findViewById<Button>(R.id.button1);
var button2 = findViewById<Button>(R.id.button2);
button1.setOnClickListener {
navController?.navigate(R.id.action_fragmentMain_to_fragmentSecond);
}
button2.setOnClickListener {
navController?.navigate(R.id.action_fragmentSecond_to_fragmentThird);
}
}
}
エッセ模範foi bem bは、Sicoをします.Hは、muto o que oを探索します.Código Completo
Reference
この問題について(Jetpackのナビゲーション), 我々は、より多くの情報をここで見つけました https://dev.to/dgbarreto/jetpack-compose-navigation-ba4テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol