【问题标题】:I have no clue as how to set string path我不知道如何设置字符串路径
【发布时间】: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)

我搜索了各种链接,所有链接都建议添加资产文件夹,但我不知道在哪里制作资产文件夹以及在其中存储什么。 请帮助我了解有关资产和字体的所有详细信息。

我还是得到了这个。

【问题讨论】:

标签: android fonts assets libraries


【解决方案1】:

您必须根据以下路径创建名为fonts的文件夹:

your_android_project_folder > app > src > main > assets > fonts

现在在您的 fonts 文件夹中,您需要存储您的 myfont.ttf 文件。

【讨论】:

  • 选项里可以看到图片素材和矢量素材,应该选哪个?
  • @Vipin 您还会在其中找到创建目录的选项。只需创建一个名为 fonts 的目录即可。
  • 完成。但是由于我使用的是第三方库,所以我没有 myfonts.ttf。请指导我如何获得它。?
  • 在这里查看 DROID_LOGO:github.com/ViksaaSkool/AwesomeSplash/blob/master/app/src/main/…。由于某种原因无法识别此 DROID_LOGO。请尝试清理并重建您的项目。
  • 成功了。我创建了 Constants 类并编写了相同的代码并且它有效。谢啦。由于我的积分非常少,因此我的赞成票不算数。仍在投票。
【解决方案2】:

我遇到了同样的问题,我是这样解决的:

  1. 对于缺少的 DROID_LOGO,您可以从这里重写该行:

    configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO);

到这个:

configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO);

在这里,请确保将 Constants.java 类添加到您的项目中,该类位于 here

  1. 对于缺少的字体,转到该行

    configSplash.setTitleFont("fonts/myfont.ttf"); //为位于 assets/fonts/ 中的字体提供字符串

并将 myfont.ttf 替换为您的 assets/font 文件夹中存在的另一种字体,例如 fonts/diti_sweet.ttf(可以在 AwesomeSplash 存储库中找到),并且一切都可以正常工作

【讨论】:

    【解决方案3】:

    注释掉这一行:

    configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO);
    

    并将 myfont.ttf 重命名为文件夹 assets 中的字体。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-18
      • 1970-01-01
      • 1970-01-01
      • 2017-01-02
      • 2016-10-04
      • 2017-04-28
      • 1970-01-01
      相关资源
      最近更新 更多