Seçili Rotayı Vurgulama
Seçimi geri yığınıyla eşitleyin.
Seçili Rotayı Vurgulama, CoddyKit'te ücretsiz bir Jetpack Compose Academy dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Jetpack Compose Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Jetpack Compose Academy kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Selection Must Be Real
A tab should light up because of where the user actually is, not a value you set by hand. The back stack is your source of truth. 🧭
Read the Current Entry
Ask the NavController for the live currentBackStackEntryAsState. It updates automatically every time navigation changes.
val entry by navController.currentBackStackEntryAsState()Get the Active Route
From that entry you read the active route string off its destination. That string tells you which tab is showing.
val route = entry?.destination?.routeCompare to Mark Selected
Now set each item selected by comparing the active route to that tab route. The match becomes the highlighted selected tab.
selected = route == tab.routeHierarchy Beats Equality
For nested graphs, exact equality can miss. Checking the destination hierarchy marks a tab active even on its sub-screens.
selected = entry?.destination?.hierarchy?.any {
it.route == tab.route
} == trueNavigate on Tap
In onClick, call navController.navigate with the tab route to move there. The selection then follows the back stack on its own.
onClick = { navController.navigate(tab.route) }Avoid Stacking Copies
Tapping a tab repeatedly should not pile up screens. Use launchSingleTop so only one copy of a destination stays on top.
navController.navigate(tab.route) {
launchSingleTop = true
}Pop to the Start
Pressing back from any tab should return to your home tab, not walk every tab you visited. popUpTo the start destination fixes that.
popUpTo(navController.graph.startDestinationId) {
saveState = true
}Tint the Active Tab
NavigationBarItem auto-tints the selected item, but you can theme it with colors so the active tab matches your brand.
colors = NavigationBarItemDefaults.colors(
selectedIconColor = MaterialTheme.colorScheme.primary
)Label Visibility
Use alwaysShowLabel to decide if unselected tabs still show text. Showing only the active label is a common clean look.
alwaysShowLabel = falseOne Reactive Loop
Put it together: read the route once, then in your forEach compare each tab to it. Selection now mirrors navigation perfectly.
Quick Check
You wired selection to the back stack. One quick question.
Recap
You synced highlighting to the back stack: read the current route, compare per tab, navigate with launchSingleTop and popUpTo. Selection now stays honest. 🎯
Yapay zeka eğitmeniyle Kotlin öğren — ücretsiz
Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.
- Kurslar
- 30
- Dersler
- 120
Sıkça Sorulan Sorular
“Seçili Rotayı Vurgulama” dersi ücretsiz mi?
Evet — “Seçili Rotayı Vurgulama” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Jetpack Compose Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Jetpack Compose Academy kursu toplamda 4 dersten oluşur.
“Seçili Rotayı Vurgulama” dersinde ne öğreneceğim?
Seçimi geri yığınıyla eşitleyin. Jetpack Compose Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Jetpack Compose Academy öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Jetpack Compose Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.
“Seçili Rotayı Vurgulama” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Jetpack Compose Academy dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Jetpack Compose Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Birden Çok Sekmeli NavigationBar
- Seçili Rotayı Vurgulama
- Geçişte Sekme Durumunu Koruma
- TabRow ve Kaydırılabilir Sayfalar