Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.dice
- import android.os.Bundle
- import androidx.activity.ComponentActivity
- import androidx.activity.compose.setContent
- import androidx.compose.foundation.Image
- import androidx.compose.foundation.layout.*
- import androidx.compose.material.Button
- import androidx.compose.material.MaterialTheme
- import androidx.compose.material.Surface
- import androidx.compose.material.Text
- import androidx.compose.runtime.Composable
- import androidx.compose.runtime.remember
- import androidx.compose.ui.Alignment
- import androidx.compose.ui.Modifier
- import androidx.compose.ui.modifier.modifierLocalOf
- import androidx.compose.ui.res.painterResource
- import androidx.compose.ui.res.stringResource
- import androidx.compose.ui.tooling.preview.Preview
- import androidx.compose.ui.unit.dp
- import com.example.dice.ui.theme.DiceTheme
- class MainActivity : ComponentActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContent {
- DiceTheme {
- Dice()
- }
- }
- }
- }
- @Preview(showBackground = true)
- @Composable
- fun Dice(){
- DiceWithButtonAndImage(modifier = Modifier
- .fillMaxSize()
- .wrapContentSize(Alignment.Center))
- }
- @Composable
- fun DiceWithButtonAndImage(modifier: Modifier = Modifier){
- var result by remember {1}
- Column (modifier = modifier,
- horizontalAlignment = Alignment.CenterHorizontally)
- {
- Image( painter = painterResource(id = R.drawable.dice_1), contentDescription = "1")
- Spacer(modifier = modifier.height(16.dp))
- Button(onClick = { result = (1..6).random() }) {
- Text(stringResource(R.string.roll))
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement