【问题标题】:Making MagicTextView a library causing R can not resolved to a variable使 MagicTextView 成为导致 R 无法解析为变量的库
【发布时间】:2013-12-09 10:06:19
【问题描述】:

我试图将 MagicTextView 导入到我的项目中,以便让 TextView 的内部流可见。我使用 File->import->Existing Project 将其导入工作区,并通过单击项目属性的“Android”选项卡的“Is Library”使其成为库。

然后我打开我的项目转到 Property 的 Android 属性并单击添加并将 MagicTextView 添加为库,然后我收到 R 无法解析为我的项目中的变量导致 MagicTextView 中出现以下 xml 错误。

 error: No resource identifier found for attribute 'strokeWidth' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:30 - CCC] /home/asutosh/workspace/MagicTextView/res/layout /main.xml:10: error: No resource identifier found for attribute 'foreground' in package   'com.qwerjk.better_text'
[2013-12-09 14:49:30 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'innerShadowDy' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:30 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'innerShadowColor' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:30 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'innerShadowRadius' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:30 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'outerShadowDy' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:30 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'outerShadowColor' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:30 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'outerShadowRadius' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:30 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'strokeColor' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:30 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'strokeJoinStyle' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:30 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'strokeWidth' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:31 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'foreground' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:31 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'innerShadowDy' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:31 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'innerShadowColor' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:31 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'innerShadowRadius' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:31 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'outerShadowDy' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:31 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'outerShadowColor' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:31 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'outerShadowRadius' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:31 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'strokeColor' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:31 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'strokeJoinStyle' in package 'com.qwerjk.better_text'
[2013-12-09 14:49:31 - CCC] /home/asutosh/workspace/MagicTextView/res/layout/main.xml:10: error: No resource identifier found for attribute 'strokeWidth' in package 'com.qwerjk.better_text'

然而,所有这些属性都在 res 中的值 attr 中定义。

【问题讨论】:

    标签: android textview rjava


    【解决方案1】:

    我也遇到了同样的问题.. 不要将其用作库。复制 MagicTextView.java 文件和您项目中的所有相关资源,然后使用它。它会成功的。

    【讨论】:

    • 我应该在我想要显示 TextView 的 xml 文件中写什么而不是下面这些行 schemas.android.com/apk/res/com.qwerjk.better_text"
    • 用您粘贴此 MagicTextView.java 文件的路径替换“com.qwerjk.better_text.MagicTextView”,其余部分保持不变。
    • Abhishek Shukla :- 它显示 Unbounf 前缀,解析 xml 错误我将上面的内容替换为 schemas.android.com/apk/res/com.example.sss"
    • 去掉xmlns这一行再看
    • 一种解决方法是以编程方式创建对象。然后将其添加到布局中。 .some what like in below answer
    【解决方案2】:

    像这样:

    popUpScoreTextView = new MagicTextView(myContext);
        // popUpScoreTextView.addInnerShadow(0, -1, 0, 0xFFffffff);
        popUpScoreTextView.addOuterShadow(9, 0, 2, Color.BLACK);
        popUpScoreTextView.setStroke(2, Color.parseColor("#612d00"));
        popUpScoreTextView.setTypeface(MyTypfaces.get(myContext, "GROBOLD"));
        popUpScoreTextView.setTextSize(40);
        popUpScoreTextView.setTextColor(Color.parseColor("#ffb400"));
        RelativeLayout.LayoutParams popupScoreTextViewParams = new RelativeLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        popupScoreTextViewParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        popUpScoreTextView.setLayoutParams(popupScoreTextViewParams);
        // ((GamePlayActivity)myContext).addContentView(popUpScoreTextView,
        // popupScoreTextViewParams);
        popUpScoreTextView.setVisibility(TextView.INVISIBLE);
    
        if (popUpScoreTextView.getParent() != null)
            ((ViewGroup) popUpScoreTextView.getParent())
                    .removeView(popUpScoreTextView);
    
        // popUpScoreTextView.setTypeface(Typeface.SANS_SERIF,
        // Typeface.BOLD_ITALIC);
        ((RelativeLayout) this.getParent()).addView(popUpScoreTextView);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多