Friday, April 23, 2021

jetpack compose - TextButton

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.Share
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)
        ) {
            TextButton(
                onClick = {
                    // do something here
                }
            ) {
                Text(text = "Share Me")
            }

            TextButton(
                onClick = {
                    // do something here
                },
                colors = ButtonDefaults.textButtonColors(
                    backgroundColor = Color(0xFFE63E62),
                    contentColor = Color(0xFFFFE5B4),
                    disabledContentColor = Color(0xFF701C1C)
                ),
                enabled = true
            ) {
                Text(text = "Share Me")
            }

            TextButton(
                onClick = {
                    // do something here
                }
            ) {
                Icon(
                    imageVector = Icons.Filled.Share,
                    contentDescription = "",
                    modifier = Modifier.padding(end = 8.dp)
                )
                Text(text = "Share Me")
            }
        }
    }


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