Advertisement
backlight0815

Untitled

Dec 1st, 2022
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. package com.example.dice
  2.  
  3. import android.os.Bundle
  4. import androidx.activity.ComponentActivity
  5. import androidx.activity.compose.setContent
  6. import androidx.compose.foundation.Image
  7. import androidx.compose.foundation.layout.*
  8. import androidx.compose.material.Button
  9. import androidx.compose.material.MaterialTheme
  10. import androidx.compose.material.Surface
  11. import androidx.compose.material.Text
  12. import androidx.compose.runtime.Composable
  13. import androidx.compose.runtime.remember
  14. import androidx.compose.ui.Alignment
  15. import androidx.compose.ui.Modifier
  16. import androidx.compose.ui.modifier.modifierLocalOf
  17. import androidx.compose.ui.res.painterResource
  18. import androidx.compose.ui.res.stringResource
  19. import androidx.compose.ui.tooling.preview.Preview
  20. import androidx.compose.ui.unit.dp
  21. import com.example.dice.ui.theme.DiceTheme
  22.  
  23. class MainActivity : ComponentActivity() {
  24. override fun onCreate(savedInstanceState: Bundle?) {
  25. super.onCreate(savedInstanceState)
  26. setContent {
  27. DiceTheme {
  28. Dice()
  29.  
  30. }
  31.  
  32. }
  33. }
  34. }
  35. @Preview(showBackground = true)
  36. @Composable
  37. fun Dice(){
  38. DiceWithButtonAndImage(modifier = Modifier
  39. .fillMaxSize()
  40. .wrapContentSize(Alignment.Center))
  41.  
  42. }
  43.  
  44. @Composable
  45. fun DiceWithButtonAndImage(modifier: Modifier = Modifier){
  46. var result by remember {1}
  47. Column (modifier = modifier,
  48. horizontalAlignment = Alignment.CenterHorizontally)
  49. {
  50. Image( painter = painterResource(id = R.drawable.dice_1), contentDescription = "1")
  51. Spacer(modifier = modifier.height(16.dp))
  52. Button(onClick = { result = (1..6).random() }) {
  53. Text(stringResource(R.string.roll))
  54.  
  55. }
  56. }
  57.  
  58.  
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement