【问题标题】:Invalid resource directory name "font" Xamarin Android无效的资源目录名称“字体”Xamarin Android
【发布时间】:2018-05-06 07:06:19
【问题描述】:

我刚刚升级了 Visual Studio for mac 以支持 Android 8 / api 26。我将 AppCompat 库更新到 26.1 以使用我的 Android 项目的 Resources 目录中的新字体文件夹。现在,当我尝试编译时,我得到路径“obj/Debug/res/font”APT0000 的“无效资源目录名称”。

【问题讨论】:

  • 在Assets/font目录下添加字体怎么样?
  • @MilanG 原来是这样的,但是从 appcompat 版本 26 开始,可以将它们添加为资源。这就是我想要的方式。 developer.xamarin.com/guides/android/application_fundamentals/…
  • 请确保您的 build-tools 与您正在编译的 API 级别相匹配。在这种情况下,如果定位奥利奥,您需要使用build-tools 26 或更高。

标签: android xamarin fonts xamarin.android android-appcompat


【解决方案1】:

对我来说,解决方案是从 SDK 管理器中删除所有旧的 Android SDK 构建工具。现在我只安装了 api 级别 26 和 27 并且可以正常工作。

【讨论】:

  • 为我工作,不必添加新的工具版本,但必须删除所有旧版本 (
【解决方案2】:

首先始终查看有关新功能的最新 xamarin 文档。 https://developer.xamarin.com/guides/android/platform_features/introduction-to-oreo/

我很快创建了一个新的 xamarin android 项目并添加了两个不同字体的文本视图:

我的解决方案如下:

我通常会尽量避免在资源名称中使用大写字母,因为 android studio 会抱怨它。

主布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

  <TextView
    android:text="Pacifico example text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:fontFamily="@font/pacifico" />

  <TextView
  android:text="Roboto light example text"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:fontFamily="@font/roboto_light" />

</LinearLayout>

我认为你没有使用最新的平台来构建。 检查您是否使用最新平台 (Oreo) 来构建应用程序。

【讨论】:

    【解决方案3】:

    我对这个问题的解决方法是在项目文件的根目录中添加以下行

    <PropertyGroup><AndroidSdkBuildToolsVersion>27.0.3</AndroidSdkBuildToolsVersion></PropertyGroup>
    

    【讨论】:

      【解决方案4】:

      正确答案在 invalid resource directory。 您必须在资产/字体中添加字体并清理重建

      【讨论】:

        猜你喜欢
        • 2013-07-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-17
        相关资源
        最近更新 更多