【问题标题】:Button contains text & image from the Internet [android]按钮包含来自互联网的文本和图像 [android]
【发布时间】:2010-09-30 08:18:28
【问题描述】:

我如何从 Internet 获取图像和文本并为我的 android 应用程序动态制作一个按钮?然后将它们绘制在我想要的位置。 即通过Java代码

认为

【问题讨论】:

标签: android button bitmap


【解决方案1】:

下载图片和文字,然后:

button.setText(downloadedText);
button.setBackgroundDrawable(drawable);

您必须从图像中创建一个 Drawable,您可以使用 Drawable#createFromStream 来完成。

在您想要的位置绘制按钮与普通按钮没有什么不同。只需在您的 XML 中声明它(可能首先设置为 Visibility.GONE),使用 View.findViewById 获取对它的引用,然后对其执行上述操作。

【讨论】:

    猜你喜欢
    • 2014-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    相关资源
    最近更新 更多