Showing posts with label compose. Show all posts
Showing posts with label compose. Show all posts

Tuesday 28 September 2021

Android Jetpack Compose Toolbar example | Jetpack Compose TopAppBar

Hi Friends,
              Many of us looking for Toolbar example in Jetpack Compose or
TopAppBar example in Jetpack compose. Today I am going to share  you 
a sample which helps you in creating Toolbar in Jetpack compose.
Also in this tutoriail I am providing you how to create toolbar menu item using
JetPack Compose.


Source Code:


Complete Activity class


Download code from here

Hope this will help someone.
Enjoy Coding............... :)

Android Jetpack Compose Dropdown menu Example | Dropdown menu using DropdownMenu Composable

Dropdown menu:
       We are going to use DropdownMenu Composable for creating dropdown menu.



fun DropdownMenu(
expanded: Boolean,
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier,
offset: DpOffset = DpOffset(0.dp, 0.dp),
properties: PopupProperties = PopupProperties(focusable = true),
content: @Composable ColumnScope.() -> Unit
)

In Above code if expanded is true, the popup menu with dropdown content will be shown.
onDismissRequest will be called when the menu should be dismiss,
@Composable
fun DropdownDemo() {
    var expanded by remember { mutableStateOf(false) }
    val items = listOf(
        "Apple", "Banana", "Cherry", "Grapes",
        "Mango", "Pineapple", "Pear"
    )
    var selectedIndex by remember { mutableStateOf(0) }
    Column(
        modifier = Modifier
            .fillMaxSize()
            .wrapContentSize(Alignment.TopStart)
            .padding(all = 5.dp)
    ) {
        Text(
            items[selectedIndex],
            modifier = Modifier
                .fillMaxWidth()
                .clickable(onClick = { expanded = true })
                .background(
                    Color.Red
                ),
            color = Color.White,
            fontSize = 20.sp,
            textAlign = TextAlign.Start
        )
        DropdownMenu(
            expanded = expanded,
            onDismissRequest = { expanded = false },
            modifier = Modifier
                .fillMaxWidth()
                .background(
                    Color.Gray
                )
        ) {
            items.forEachIndexed { index, s ->
                DropdownMenuItem(onClick = {
                    selectedIndex = index
                    expanded = false
                }) {
                    Text(text = s)
                }
            }
        }
    }
}

Hope this will help someone.
Enjoy Coding.......... :)

Friday 24 September 2021

Android Jetpack Compose Button Example | How to center a button in jetpack Compose | How to onclick listener on button in Jetpack Compose

Hi Friends,
             Today I am sharing a Sample of Jetpack Compose Button view. I will show you how
to set onclick listener on button in Jetpack Compose. How to style on Button in
Jetpack Compse , how to set height and width of button in Jetpack compose.

  Code:
   

  Hope this will help someone.
  Enjoy Coding........... :) 





Android Jetpack compose- Android Listview using Jetpack compose | Jetpack compose listview clicklistener

 Hello all, 
        Today I am going to share my anothere Android Jetpack Compose tutoria.
How to set clicklistener on listview in android Jetpack Compses, how to set clicklistener 
on button using Jetpack Compse.



I am sharing below code where I am handling list item click in jetpack compose.


Downlaod complete code from here
Hope this will help someone.
Enjoy Coding....... :)

Android Jetpack Compose Alert Dialog Sample | Jetpack Compose Dialog

 Hi Friends,  
               Today I am sharing the Jetpack Compse Alert Dialog Sample.

What is Alert Dialog?
- Alert dialog is a Dialog which interrupts the user with 
urgent information, details or actions.


Code:

Hope this will help someone.
Enjoy Coding........ :)



Tuesday 21 September 2021

Android Jetpack- Composable functions




Jetpack Compose is built around composable functions. These functions
let you define your app's UI programmatically by describing how it
should look and providing data dependencies, rather than 
focusing on the process of the UI's construction (initializing an 
element, attaching it to a parent, etc.).
To create a composable function, just add the @Composable annotation
to the function name.




Enjoy Coding.... :)

 

Copyright @ 2013 Android Developers Blog.