小编MAR*_*RK 的帖子

如何以编程方式设置组合矢量图标的色调模式和色调颜色

我有一些从 SVG 转换而来的矢量图标,我需要根据某些条件为它们自定义色调颜色,我正在尝试以编程方式更改色调颜色

Image(
        modifier = Modifier.size(128.dp),
        painter = painterResource(id = R.drawable.icon_1),
        contentDescription = null,
        colorFilter =  ColorFilter.tint(Color.Red)
    )
Run Code Online (Sandbox Code Playgroud)

它给了我以下结果

结果

另外,当我尝试使用

Image(
    modifier = Modifier.size(128.dp),
    painter = painterResource(id = R.drawable.icon_1),
    contentDescription = null,
    colorFilter =  ColorFilter.tint(Color.Red, blendMode = BlendMode.Multiply)
)
Run Code Online (Sandbox Code Playgroud)

我也得到了同样的结果。但是,当我尝试通过添加来更改 XML 文件中的图标色调时

android:tint="@color/red"
android:tintMode="multiply"
Run Code Online (Sandbox Code Playgroud)

它正确地给了我想要的结果,如下所示

在此输入图像描述

那么,当我需要根据某些条件以编程方式将颜色更改为不同颜色时,如何才能以编程方式实现相同的结果呢?

android-vectordrawable android-jetpack-compose

7
推荐指数
1
解决办法
2542
查看次数

意图打开URL

在我的应用程序中,我收到用户插入的URL.该URL可以是 - 例如 - xx.sd.使用任何Web浏览器,此URL都是有效的URL,但是当尝试按意图打开它时,会发生崩溃:android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=xx.sd }.
我使用此检查此URL是有效的URL

Patterns.WEB_URL.matcher(model.getTarget().getUrl()).matches()
Run Code Online (Sandbox Code Playgroud)

并使用此代码打开意图

  Intent i = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(model.getTarget().getUrl()));
  itemView.getContext().startActivity(i);
Run Code Online (Sandbox Code Playgroud)

我知道我可以通过追加httphttps在URL之前解决此问题(如果不存在)但是如果我的URL以其他协议ftpfile其他协议开头.任何人都可以帮我解决这个问题.

url android android-intent

1
推荐指数
1
解决办法
2万
查看次数