Browse Source

basic 2 screen setup

master
Xaver 1 week ago
parent
commit
296754a28f
  1. 1
      .idea/gradle.xml
  2. 7
      app/build.gradle.kts
  3. 67
      app/src/main/java/at/xaxa/demonstrator2/MainActivity.kt
  4. 10
      gradle/libs.versions.toml

1
.idea/gradle.xml

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>

7
app/build.gradle.kts

@ -5,12 +5,12 @@ plugins {
android { android {
namespace = "at.xaxa.demonstrator2" namespace = "at.xaxa.demonstrator2"
compileSdk = 34 compileSdk = 35
defaultConfig { defaultConfig {
applicationId = "at.xaxa.demonstrator2" applicationId = "at.xaxa.demonstrator2"
minSdk = 24 minSdk = 24
targetSdk = 34 targetSdk = 35
versionCode = 1 versionCode = 1
versionName = "1.0" versionName = "1.0"
@ -50,6 +50,8 @@ android {
} }
dependencies { dependencies {
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.material)
implementation(libs.androidx.core.ktx) implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx) implementation(libs.androidx.lifecycle.runtime.ktx)
@ -59,6 +61,7 @@ dependencies {
implementation(libs.androidx.ui.graphics) implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview) implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3) implementation(libs.androidx.material3)
implementation(libs.androidx.legacy.support.v4)
testImplementation(libs.junit) testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core) androidTestImplementation(libs.androidx.espresso.core)

67
app/src/main/java/at/xaxa/demonstrator2/MainActivity.kt

@ -4,13 +4,26 @@ import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.Home
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import at.xaxa.demonstrator2.ui.theme.Demonstrator2Theme import at.xaxa.demonstrator2.ui.theme.Demonstrator2Theme
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
@ -19,12 +32,7 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdge() enableEdgeToEdge()
setContent { setContent {
Demonstrator2Theme { Demonstrator2Theme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> NavigationBar()
Greeting(
name = "Android",
modifier = Modifier.padding(innerPadding)
)
}
} }
} }
} }
@ -45,3 +53,50 @@ fun GreetingPreview() {
Greeting("Android") Greeting("Android")
} }
} }
@Composable
fun NavigationBar() {
val navController = rememberNavController()
Scaffold(
bottomBar = {
NavigationBar {
NavigationBarItem(
icon = { Icon(Icons.Default.Home, contentDescription = "Home") },
label = { Text("Home") },
selected = navController.currentBackStackEntryAsState().value?.destination?.route == "home",
onClick = { navController.navigate("home") }
)
NavigationBarItem(
icon = { Icon(Icons.Default.Favorite, contentDescription = "Favorites") },
label = { Text("Favorites") },
selected = navController.currentBackStackEntryAsState().value?.destination?.route == "favorites",
onClick = { navController.navigate("favorites") }
)
}
}
) { innerPadding ->
NavHost(
navController = navController,
startDestination = "home",
modifier = Modifier.padding(innerPadding)
) {
composable("home") { HomeScreen() }
composable("favorites") { FavoritesScreen() }
}
}
}
@Composable
fun HomeScreen() {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text("Home Screen")
}
}
@Composable
fun FavoritesScreen() {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text("Favorites Screen")
}
}

10
gradle/libs.versions.toml

@ -8,9 +8,17 @@ espressoCore = "3.6.1"
lifecycleRuntimeKtx = "2.8.7" lifecycleRuntimeKtx = "2.8.7"
activityCompose = "1.9.3" activityCompose = "1.9.3"
composeBom = "2024.04.01" composeBom = "2024.04.01"
legacySupportV4 = "1.0.0"
material = "1.7.5"
material3 = "1.2.0"
navigationCompose = "2.8.4"
navigationComposeVersion = "2.7.2"
[libraries] [libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
androidx-material = { module = "androidx.compose.material:material", version.ref = "material" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
androidx-navigation-compose-v272 = { module = "androidx.navigation:navigation-compose", version.ref = "navigationComposeVersion" }
junit = { group = "junit", name = "junit", version.ref = "junit" } junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
@ -24,6 +32,8 @@ androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-toolin
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" } androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" } androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-legacy-support-v4 = { group = "androidx.legacy", name = "legacy-support-v4", version.ref = "legacySupportV4" }
material3 = { module = "androidx.compose.material3:material3", version.ref = "material3" }
[plugins] [plugins]
android-application = { id = "com.android.application", version.ref = "agp" } android-application = { id = "com.android.application", version.ref = "agp" }

Loading…
Cancel
Save