Friday, March 5, 2021

jetpack compose - Extended floating action button example

MainActivity.kt

package com.cfsuman.jetpackcompose

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.padding
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.runtime.Composable
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(){
        ExtendedFloatingActionButton(
            text = { Text("Like Us")},
            onClick = {
                Toast.makeText(
                    this,
                    "Clicked",
                    Toast.LENGTH_SHORT
                ).show()
            },
            icon = { Icon(
                Icons.Filled.Favorite,
                "Localized description",
                tint = Color(0xFFCCFF00)
            )},
            elevation = FloatingActionButtonDefaults.elevation(8.dp),
            backgroundColor = Color(0xFFFF9933),
            contentColor = Color.White,
            modifier = Modifier.padding(16.dp)
        )
    }


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