Android - Forecast.io 图标标签自定义字体 : weather-icons

标签 android fonts icons retrofit

我目前正在使用 forecast.io api 构建一个天气应用程序。 他们提供custom font for Forecast.io ,以及其他 api,例如 Yahoo。我不确定如何继续使用他们的 API mapping .

例如,我收到“partly-cloudy-night”,这应该呈现图标。

我欢迎提供有关如何进行的建议或线索。

非常感谢,

最佳答案

您必须在您的 android 项目中使用 ttf 文件,并将 css 转换为 xml 字符串资源。 我为 Web Hosting hub 字形做了这件事(有点像很棒的字体,但还有更多图标)。

参见 https://github.com/neoteknic/whhg-to-android

我可以重用我的转换脚本并使用这些图标创建一个 repo。

编辑: 这是给您的 : https://github.com/neoteknic/weather-icons-to-android

要使用它(我更喜欢只加载一次字体并使其在全局范围内可用):

public class YourAppName extends Application {
    public static Typeface weatherIcons;

    @Override
    public void onCreate(){
YourAppName.weatherIcons= Typeface.createFromAsset(getApplicationContext().getResources().getAssets(), "fonts/weathericons-regular-webfont.ttf");
        super.onCreate();
    }
}

然后当你想使用它时:

TextView myicon=(TextView) findViewById(R.id.myicon);
myicon.setTypeface(YourAppName.weatherIcons);
myicon.setText(R.string.wi_day_snow_wind);

关于Android - Forecast.io 图标标签自定义字体 : weather-icons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38232997/

相关文章:

android - 如何使用 jobb 工具创建 OBB 文件 Android

android - MPAndroidChart:我可以为 x 轴标签设置不同的颜色吗?

c - 我的文字在哪里?

html - 仅为数字设置字体系列

java - 如何使用 awt/关闭窗口按钮?

windows - 将多个 PNG 文件制作成一个 ICO 文件

Java ArrayList 性能

android - 缩短 Firebase 动态链接

android - 无法在Android应用程序中显示菜单图标

java - EditText的错误信息图标可以更改吗?