【发布时间】:2016-10-03 07:40:35
【问题描述】:
我正在使用第三方库来制作初始屏幕。我是从https://github.com/ViksaaSkool/AwesomeSplash 那里得到的。我已按照整个教程进行操作,但在设置字符串路径时出现错误。它有一条线 "configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO); //设置路径字符串"。 Android Studio 无法解析 DROID_LOGO,我收到错误消息。我用 DATA 替换了 DROID_LOGO 并得到了这个错误。 正如帖子中所建议的,我已经编写了这段代码。
public class splashex extends AwesomeSplash {
//DO NOT OVERRIDE onCreate()!
//if you need to start some services do it in initSplash()!
@Override
public void initSplash(ConfigSplash configSplash) {
/* you don't have to override every property */
//Customize Circular Reveal
configSplash.setBackgroundColor(R.color.colorPrimary); //any color you want form colors.xml
configSplash.setAnimCircularRevealDuration(2000); //int ms
configSplash.setRevealFlagX(Flags.REVEAL_RIGHT); //or Flags.REVEAL_LEFT
configSplash.setRevealFlagY(Flags.REVEAL_BOTTOM); //or Flags.REVEAL_TOP
//Choose LOGO OR PATH; if you don't provide String value for path it's logo by default
//Customize Logo
configSplash.setLogoSplash(R.mipmap.ic_launcher); //or any other drawable
configSplash.setAnimLogoSplashDuration(2000); //int ms
configSplash.setAnimLogoSplashTechnique(Techniques.Bounce); //choose one form Techniques (ref: https://github.com/daimajia/AndroidViewAnimations)
//Customize Path
configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO); //set path String(**I am getting error here**)
// configSplash.setOriginalHeight(400); //in relation to your svg (path) resource
configSplash.setOriginalWidth(400); //in relation to your svg (path) resource
configSplash.setAnimPathStrokeDrawingDuration(3000);
configSplash.setPathSplashStrokeSize(3); //I advise value be <5
configSplash.setPathSplashStrokeColor(R.color.colorPrimaryDark); //any color you want form colors.xml
configSplash.setAnimPathFillingDuration(3000);
configSplash.setPathSplashFillColor(R.color.colorPrimaryDark); //path object filling color
//Customize Title
configSplash.setTitleSplash("My Awesome App");
configSplash.setTitleTextColor(R.color.colorAccent);
configSplash.setTitleTextSize(30f); //float value
configSplash.setAnimTitleDuration(3000);
configSplash.setAnimTitleTechnique(Techniques.FlipInX);
configSplash.setTitleFont("fonts/myfont.ttf"); //provide string to your font located in assets/fonts/
}
@Override
public void animationsFinished() {
//transit to another activity here
//or do whatever you want
}
}
我得到的错误是
java.lang.RuntimeException: Font asset not found fonts/myfont.ttf
at android.graphics.Typeface.createFromAsset(Typeface.java:190)
我搜索了各种链接,所有链接都建议添加资产文件夹,但我不知道在哪里制作资产文件夹以及在其中存储什么。 请帮助我了解有关资产和字体的所有详细信息。
我还是得到了这个。
【问题讨论】:
-
请提供一些示例代码以确保您的解决方案?
-
我已经添加了代码。
-
可能是您没有合适的 setTitleFont 字符串,因此您可以使用 stackoverflow.com/questions/16110002/read-assets-file-as-string 获取字符串
-
并确保您在要设置的资产和字体中有一个字体文件夹
标签: android fonts assets libraries