Итак, я сделал этот код в Android Studio (простой код). Это файл main.kt -< /p>
package com.example.superheros
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.compose.SuperherosTheme
import com.example.superheros.model.Hero
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
SuperherosTheme {
Scaffold(modifier = Modifier.fillMaxSize()) {
Text(text = "Superheros", modifier = Modifier.padding(it))
}
}
}
}
}
@Preview(showBackground = true)
@Composable
fun ListItemPreview() {
val sampleHero = Hero(
nameRes = R.string.hero1, // Add in strings.xml
descriptionRes = R.string.description1, // Add in strings.xml
imageRes = R.drawable.android_superhero1 // Add in drawable
)
ListItem(hero = sampleHero)
}
< /code>
и я добавил несколько шрифтов, используя файл type.kt-< /p>
package com.example.superheros.ui.theme
import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import com.example.superheros.R
import androidx.compose.ui.text.font.Font
val Cabin = FontFamily(
Font(R.font.cabin_regular, FontWeight.Normal)
)
val cabinBold = FontFamily(
Font(R.font.cabin_bold, FontWeight.Bold)
)
val AppTypography = Typography(
displayLarge = TextStyle(
fontFamily = cabinBold,
fontWeight = FontWeight.Bold,
fontSize = 36.sp
),
bodyLarge = TextStyle(
fontFamily = Cabin,
fontWeight = FontWeight.Normal,
fontSize = 14.sp
)
)
< /code>
ig Я сделал файл theme.kt правильно. Описание изображения. Предполагается, что это будет шрифт кабины. Затем я попытался использовать ИИ и внес некоторые изменения в main.kt и type.kt, например, изменение структуры кода Type.kt, но не получил исключенный результат.
Подробнее здесь: https://stackoverflow.com/questions/797 ... -in-kotlin