我目前正在使用 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/