Dec 11, 2023

Minimal starting template for Android Compose

Find a simple minimal code to open an app with top and bottom bar. Find full code on https://github.com/Wiseland-Inc/dev.androidauthority.app

Minimal starting template for Android Compose
package dev.androidauthority.app

import android.os.Bundle
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountBox
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.remember
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.mutableStateOf
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults.largeTopAppBarColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.google.android.engage.common.datamodel.Image
import dev.androidauthority.app.ui.theme.ReaderTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            ReaderTheme {
                ScaffoldExample()
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    Text(
        text = "Hello $name!",
        modifier = modifier
    )
}

@Composable
@OptIn(ExperimentalMaterial3Api::class)
@Preview
fun ScaffoldExample() {
    var presses by remember { mutableStateOf(0) }

    Scaffold(
        topBar = {
            TopAppBar(
                colors = largeTopAppBarColors(
                    containerColor = MaterialTheme.colorScheme.primaryContainer,
                    titleContentColor = MaterialTheme.colorScheme.primary,
                ),
                title = {
                    Text("Top app bar")
                }
            )
        },
        bottomBar = {
            BottomAppBar(
                containerColor = MaterialTheme.colorScheme.primaryContainer,
                contentColor = MaterialTheme.colorScheme.primary,
                actions = {
                    IconButton(onClick = { /* do something */ }) {
                        Icon(Icons.Filled.Check, contentDescription = "Localized description")
                    }
                    IconButton(onClick = { /* do something */ }) {
                        Icon(
                            Icons.Filled.Edit,
                            contentDescription = "Localized description",
                        )
                    }
                    IconButton(onClick = { /* do something */ }) {
                        Icon(
                            Icons.Filled.AccountBox,
                            contentDescription = "Localized description",
                        )
                    }
                    IconButton(onClick = { /* do something */ }) {
                        Icon(
                            Icons.Filled.Favorite,
                            contentDescription = "Localized description",
                        )
                    }
                }
            )
        },
        floatingActionButton = {
            FloatingActionButton(onClick = { presses++ }) {
                Icon(Icons.Default.Add, contentDescription = "Add")
            }
        }
    ) { innerPadding ->
        Column(
            modifier = Modifier
                .padding(innerPadding),
            verticalArrangement = Arrangement.spacedBy(16.dp),
        ) {
            Text(
                modifier = Modifier.padding(8.dp),
                text =
                """
                    This is an example of a scaffold. It uses the Scaffold composable's parameters to create a screen with a simple top app bar, bottom app bar, and floating action button.

                    It also contains some basic inner content, such as this text.

                    You have pressed the floating action button $presses times.
                """.trimIndent(),
            )
        }
    }
}



@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    ReaderTheme {
        Greeting("Android")
    }
}

https://github.com/Wiseland-Inc/dev.androidauthority.app

Continue Reading
Learn about other front end technologies

Learn about other front end technologies

We are partnering with Frontendeng.dev to cross promote the content around front end engineering.

Published Dec 12, 2023

Android paired with Windows Laptops

Android paired with Windows Laptops

The new trend is to build Android and Windows Laptop into one hardware.

Published Jan 11, 2024

What are co-routines in Kotlin ? Kotlin for Android Part -2

What are co-routines in Kotlin ? Kotlin for Android Part -2

In this part we will learn about Kotlin's co-routines. It is an important concurrency design pattern that is extremely useful when designing asynchronous programs.

Published Dec 31, 2023

Backends for your Android App

Backends for your Android App

In this article, we will explore the various options available for app developers who are primarily focused on building an app backend.

Published Jan 1, 2024

Google Flutter vs Android Jetpack Compose : A detailed comparison

Google Flutter vs Android Jetpack Compose : A detailed comparison

Flutter code looks remarkably similar to Android Jetpack Compose. However which one of them is better ? We find out in this article.

Published Jan 11, 2024

Spring Boot for App Backends

Spring Boot for App Backends

Simple spring boot template to deploy on Google Cloud and to be used as your app backend.

Published Jan 6, 2024

Learning Kotlin for Android development - Part 1

Learning Kotlin for Android development - Part 1

A guide focused on teaching you basics of Kotlin just for Android development.

Published Dec 7, 2023

Making android development less painful

Making android development less painful

Android development has always been challenging and frustrating right from start. However things are looking better now.

Published Dec 4, 2023

Understanding Layouts in Android Compose

Understanding Layouts in Android Compose

A very quick tutorial on compose and layouts.

Published Dec 10, 2023

What are adaptive android apps ?

What are adaptive android apps ?

Adaptive apps are app equivalent of responsive web apps. Apps that resize to give good user experience across several devices.

Published Dec 9, 2023