Friday, April 23, 2021

jetpack compose - Outlined Button

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.foundation.layout.Column
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.runtime.*
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(){
        Column(
            Modifier
                .background(Color(0xFFEDEAE0))
                .fillMaxSize()
                .padding(32.dp),
            verticalArrangement = Arrangement.spacedBy(24.dp)
        ) {
            OutlinedButton(
                onClick = {
                    // do something here
                }
            ) {
                Text(text = "Like Me")
            }

            OutlinedButton(
                onClick = {
                    // do something here
                },
                colors = ButtonDefaults.outlinedButtonColors(
                    backgroundColor = Color(0xFF7BB661),
                    contentColor = Color(0xFFF5F5F5),
                    disabledContentColor = Color(0xFF666699)
                ),
                enabled = true
            ) {
                Text(text = "Like Me")
            }

            OutlinedButton(
                onClick = {
                    // do something here
                }
            ) {
                Icon(
                    imageVector = Icons.Filled.Favorite,
                    contentDescription = "Localized description",
                    modifier = Modifier.padding(end = 8.dp)
                )
                Text(text = "Like Me")
            }
        }
    }


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