如何打开带图片的URL?

问题描述 投票:0回答:1

如何使用 Jetpack Compose 打开可点击图像上的外部 URL?

谢谢!

@Composable
fun Replay() {
    Box(
        modifier = Modifier
    )
    Row (
        modifier = Modifier
            .padding(20.dp)
            .fillMaxWidth(),
        horizontalArrangement = Arrangement.Center
    ) {
            Image(
                painter = painterResource(id = R.drawable.logoreplay),
                contentDescription = "logoreplay",
                modifier = Modifier
                    .size(130.dp)
                    .padding(10.dp)
                    .clickable { 
                        
                    }
            )

我到处寻找但没有找到答案。

android kotlin android-jetpack-compose clickable
1个回答
0
投票

创建一个用于查看 URL 的 Intent,然后使用本地 Context 打开它。

.clickable { 
    val intent = Intent(Intent.ACTION_VIEW, Uri.parse(theUrlString))
    try {
        LocalContext.current.startActivity(intent)
    } catch (e: ActivityNotFoundException) {
        // log error or take some other action, but it would be very rare for a 
        // device to have no browser installed
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.