我不知道如何设置字符串路径

I have no clue as how to set string path

我正在为启动画面使用第三方库。我从 https://github.com/ViksaaSkool/AwesomeSplash 得到的。我已经按照整个教程进行操作,但是在设置字符串路径时出现错误。它有一条线 "configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO); //set path String"。 Android studio 无法解析 DROID_LOGO,我遇到了错误。我用 DATA 替换了 DROID_LOGO 并得到了这个错误。 按照 post 上的建议,我已经编写了这段代码。

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)

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

我还是明白了。

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

your_android_project_folder > app > src > main > assets > fonts

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

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

  1. 对于缺失的DROID_LOGO,可以改写这行:

    configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO);

对此:

configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO);

在这里,确保将 Constants.java class 添加到项目中,可以在 here

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

    configSplash.setTitleFont("fonts/myfont.ttf"); //为位于 assets/fonts/

  2. 的字体提供字符串

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

注释掉这一行:

configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO);

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