I can't figure out what the problem is. I'm trying to create a button, but one of the modifier attributes doesn't work, I tried wrapping it in a column, but it doesn't help.
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
}
}
}
@Preview
@Composable
fun Greeting() {
val context = LocalContext.current
Column(
modifier = Modifier
.fillMaxSize()
.background(Color.Blue)
.padding(0.dp, 0.dp, 0.dp, 28.dp),
verticalArrangement = Arrangement.SpaceEvenly
) {
TextPlayList(str = R.string.main_text_Playlist_Maker)
Button(
onClick = { context.startActivity(Intent(context, SearchMain::class.java)) },
colors = ButtonDefaults
.outlinedButtonColors(backgroundColor = Color.White),
shape = RoundedCornerShape(16.dp),
modifier = Modifier
.fillMaxWidth()
.weight(1f)
.padding(17.dp, 0.dp, 15.dp, 8.dp)
)
{
IconButton(R.drawable.ic_search_main)
TextButton(str = R.string.main_button_search)
}
Button(
onClick = { context.startActivity(Intent(context, MediaActivity::class.java)) },
colors = ButtonDefaults
.outlinedButtonColors(backgroundColor = Color.White),
shape = RoundedCornerShape(16.dp),
modifier = Modifier
.fillMaxWidth()
.weight(1f)
.padding(17.dp, 8.dp, 15.dp, 8.dp)
)
{
IconButton(R.drawable.ic_media_main)
TextButton(str = R.string.main_button_media)
}
Button(
onClick = { context.startActivity(Intent(context, SettingMain::class.java)) },
colors = ButtonDefaults
.outlinedButtonColors(backgroundColor = Color.White),
shape = RoundedCornerShape(16.dp),
modifier = Modifier
.fillMaxWidth()
.weight(1f)
.padding(17.dp, 8.dp, 15.dp, 0.dp)
)
{
IconButton(R.drawable.ic_setting_main)
TextButton(str = R.string.main_button_setting)
}
}
}
@Composable
fun ButtonMain() {
val context = LocalContext.current
Button(
onClick = { context.startActivity(Intent(context, SettingMain::class.java)) },
colors = ButtonDefaults
.outlinedButtonColors(backgroundColor = Color.White),
shape = RoundedCornerShape(16.dp),
modifier = Modifier
.weight(1f, false)
.fillMaxWidth()
.padding(17.dp, 8.dp, 15.dp, 0.dp)
) {
IconButton(draw = R.drawable.ic_setting_main)
TextButton(str = R.string.main_button_setting)
}
}
@Composable
fun IconButton(draw: Int) {
Icon(
painter = painterResource(id = draw),
"Setting",
Modifier.padding(10.dp),
tint = Color.Black
)
}
@Composable
fun TextButton(str: Int) {
Text(
text = stringResource(id = str),
fontSize = 22.sp, color = Color.Black
)
}
@Composable
fun TextPlayList(str: Int) {
Text(
text = stringResource(id = str),
fontSize = 22.sp,
color = Color.White,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp, 14.dp, 210.dp, 40.dp)
)
}
I tried to solve the problem like this, but it turns out not what I need. Modifier weight not available in jetpack compose 1.1.1