Create chip with outline Jetpack Compose

Praveen P.

I have the following composable function to build a Chip:

@Composable
fun CategoryChip(
  category: String,
  isSelected: Boolean = false,
  onSelectedCategoryChanged: (String) -> Unit,
  onExecuteSearch: () -> Unit
) {
  Surface(
    modifier = Modifier.padding(end = 8.dp, bottom = 8.dp),
    elevation = 8.dp,
    shape = RoundedCornerShape(16.dp),
    color = when {
      isSelected -> colorResource(R.color.teal_200)
      else -> colorResource(R.color.purple_500)
    }
  ) {
    Row(modifier = Modifier
      .toggleable(
        value = isSelected,
        onValueChange = {
          onSelectedCategoryChanged(category)
          onExecuteSearch()
        }
      )) {
      Text(
        text = category,
        style = MaterialTheme.typography.body2,
        color = Color.White,
        modifier = Modifier.padding(8.dp)
      )
    }
  }
}

This creates the following chip:

enter image description here

But what I am trying to achieve is the following:

enter image description here

Is it possible to create a shape like that with Jetpack Compose?

Code Poet

Yes, all you have to do is add a border to your surface.

Surface(
    modifier = Modifier.padding(end = 8.dp, bottom = 8.dp),
    elevation = 8.dp,
    shape = RoundedCornerShape(16.dp),
    border = BorderStroke(
        width = 1.dp,
        color = when {
            isSelected -> colorResource(R.color.teal_200)
            else -> colorResource(R.color.purple_500)
        }
     )
)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to change the outline color of OutlinedTextField from jetpack compose?

From Java

Center composable in Jetpack compose

From Dev

ProvideEmphasis not found in jetpack compose

From Dev

ProvideEmphasis not found in jetpack compose

From Dev

Jetpack Compose – LazyColumn not recomposing

From Dev

Create outline for adjacent shapes

From Java

Android Jetpack compose IconButton padding

From Java

Jetpack compose breaks Room compiler

From Dev

Jetpack Compose list diffs animation

From Dev

Aligning a resized TextField in Jetpack Compose

From Dev

Jetpack Compose draw on image with Painter

From Dev

How to handle navigation in Jetpack Compose?

From Java

Programmatically create a MaterialButton with Outline style

From Dev

How to create a double outline border?

From Java

Material icon size adjustment in Jetpack Compose?

From Java

Jetpack Compose State: Modify class property

From Java

How can I get onTouchEvent in Jetpack Compose?

From Java

Jetpack compose: Android Tests won't run

From Dev

How to add Image in Android using Jetpack Compose

From Dev

Button Long Press Listener in Android jetpack compose

From Dev

How to convert TextUnit to Dp in Jetpack Compose?

From Dev

How to know if Text is visible on Jetpack Compose?

From Dev

Show a new line in a Text component in Jetpack Compose

From Dev

Putting something below a LazyColumn in Jetpack Compose

From Dev

Can I write Jetpack Compose components in Java?

From Dev

Is there a way to create a CGPath matching outline of a SKSpriteNode?

From Dev

Create miniature outline view from GEF editor

From Dev

How to create a SKSpriteNode that is the circumference of a circle, just the outline?

From Dev

Create a dotted Dash effect outline in Android

Related Related

  1. 1

    How to change the outline color of OutlinedTextField from jetpack compose?

  2. 2

    Center composable in Jetpack compose

  3. 3

    ProvideEmphasis not found in jetpack compose

  4. 4

    ProvideEmphasis not found in jetpack compose

  5. 5

    Jetpack Compose – LazyColumn not recomposing

  6. 6

    Create outline for adjacent shapes

  7. 7

    Android Jetpack compose IconButton padding

  8. 8

    Jetpack compose breaks Room compiler

  9. 9

    Jetpack Compose list diffs animation

  10. 10

    Aligning a resized TextField in Jetpack Compose

  11. 11

    Jetpack Compose draw on image with Painter

  12. 12

    How to handle navigation in Jetpack Compose?

  13. 13

    Programmatically create a MaterialButton with Outline style

  14. 14

    How to create a double outline border?

  15. 15

    Material icon size adjustment in Jetpack Compose?

  16. 16

    Jetpack Compose State: Modify class property

  17. 17

    How can I get onTouchEvent in Jetpack Compose?

  18. 18

    Jetpack compose: Android Tests won't run

  19. 19

    How to add Image in Android using Jetpack Compose

  20. 20

    Button Long Press Listener in Android jetpack compose

  21. 21

    How to convert TextUnit to Dp in Jetpack Compose?

  22. 22

    How to know if Text is visible on Jetpack Compose?

  23. 23

    Show a new line in a Text component in Jetpack Compose

  24. 24

    Putting something below a LazyColumn in Jetpack Compose

  25. 25

    Can I write Jetpack Compose components in Java?

  26. 26

    Is there a way to create a CGPath matching outline of a SKSpriteNode?

  27. 27

    Create miniature outline view from GEF editor

  28. 28

    How to create a SKSpriteNode that is the circumference of a circle, just the outline?

  29. 29

    Create a dotted Dash effect outline in Android

HotTag

Archive