Код: Выделить всё
import androidx.compose.material.icons.Icons
import androidx.compose.material3.Icon

Я пытался найти эту проблему в Интернете, но безуспешно. Точно так же мне не удалось использовать фрагменты, относящиеся к значкам, которые я нашел в документации для разработчиков Android.
Вот файл MainActivity.kt для дополнительного контекста:
Код: Выделить всё
import android.graphics.drawable.Icon
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.FixedScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.sp
import com.example.buisness_card.ui.theme.Buisness_CardTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Buisness_CardTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background,
) {
Introduction(
name = "Name Goes Here",
jobDescription = "Job Description Goes Here",
)
}
}
}
}
}
@Composable // Defines the function as a composable function
fun Introduction(
// Values to be passed into the function fo
name: String,
jobDescription: String,
modifier: Modifier = Modifier,
) {
// Create a constant with a path to the profile picture
val image = painterResource(id = R.drawable.pfp3)
// Create a column as a container for other objects
Column(
// Centre all objects
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
// Unsure why this works, but ensures objects behave as desired
modifier = modifier.fillMaxSize()
) {
Image(
// Reference previously defined path to image
painter = image,
// Description for users with TalkBack enabled
contentDescription = stringResource(R.string.pfp_description),
// Sets scale of the image using a float value
contentScale = FixedScale(0.4F),
// Pass down the modifier for future child objects
modifier = modifier,
)
// Creates a new text object
Text(
// Sets value to the parameter of the function
text = name,
fontSize = 40.sp,
// Ensures proper alignment
modifier = Modifier.align(alignment = Alignment.CenterHorizontally),
)
Text(
text = jobDescription,
fontSize = 20.sp,
modifier = Modifier.align(alignment = Alignment.CenterHorizontally),
)
}
}
@Composable
fun Contact_Info(
phoneNumber: String,
github: String,
website: String,
modifier: Modifier = Modifier,
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = modifier.fillMaxSize(),
) {
Row(modifier = modifier) {
//Icon will go here
Icon(
)
}
}
}
@Composable
fun TestIcon(modifier: Modifier = Modifier) {
}
@Preview(showBackground = true, showSystemUi = true)
@Composable
fun GreetingPreview() {
Introduction(name = "Name Goes Here", jobDescription = "Job Description Goes Here")
}
Я попытался вызвать составную функцию Icon(), чтобы Я могу использовать ее в своем приложении, но попытка использовать эту функцию приводит к появлению ошибок в Android Studio, что также приводит к сбою компилятора.
Я пробовал импортировать пакеты с помощью Android Studio , но безрезультатно, что привело к ошибке: Невозможно получить доступ '': в 'Icon' он является личным для пакета. Импорт пакетов из фрагментов документации для разработчиков Android приводит к ошибкам, указывающим, что пакет не существует или имя не определено.
Подробнее здесь: https://stackoverflow.com/questions/780 ... or-the-ico