Sunday, March 7, 2021

jetpack compose - How to use Row layout

MainActivity.kt

package com.cfsuman.jetpackcompose

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            MainContent()
        }
    }


    @Composable
    fun MainContent(){
        Row(
            Modifier
                .background(Color(0xFFEDEAE0))
                .padding(16.dp)
                .fillMaxWidth(),
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.SpaceEvenly
        ) {
            Button(onClick = {
                // do something
                }
            ) {
                Text(text = "First" )
            }

            Button(onClick = { },
            colors = ButtonDefaults.textButtonColors(
                backgroundColor = Color(0xFF333399),
                contentColor = Color(0xFFF0FFFF)
            )
            ) {
                Text(text = "Second" )
            }

            Button(onClick = { },
                colors = ButtonDefaults.textButtonColors(
                    backgroundColor = Color(0xFFC32148),
                    contentColor = Color(0xFFFFFF99)
                )
            ) {
                Text(text = "Third" )
            }
        }
    }


    @Preview
    @Composable
    fun ComposablePreview(){
        //MainContent()
    }
}