【问题标题】:Couldn't resolve resource @id/visible when using TextInputLayout使用 TextInputLayout 时无法解析资源 @id/visible
【发布时间】:2017-05-09 06:31:18
【问题描述】:

在appcompat-v7:25.x.x 上使用TextInputLayout 时无法解析资源@id/visible

尝试了以下这些步骤,但问题仍然存在:

  1. 重建项目
  2. 清理和重建项目
  3. 清除缓存和 重启 Android Studio

下面是布局文件中的代码。

    <android.support.design.widget.TextInputLayout
            android:id="@+id/tilFirstName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/etFirstName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/first_name"
                android:inputType="textPersonName"/>
    </android.support.design.widget.TextInputLayout>

下面是Android Studio中显示的消息

渲染问题。

无法解析资源@id/visible

提示:尝试刷新布局。

注意:@id/visible 不存在于代码中。

【问题讨论】:

  • 您的android:id="@id/visible" 视图在哪里?
  • 我不要t know, i didnt 在代码中使用它的 id
  • 那是谁的代码?不是你的吗?
  • 我的代码,但我没有在这个布局中使用带有@id/visible 的视图
  • 可能在某些样式或主题中引用了它?

标签: android android-studio android-textinputlayout


【解决方案1】:

这很可能是一个错误,它一直是filed in the Issue Tracker。

同时,您可以尝试将编辑器中的 API 版本切换到 19 或以下,尽管you may see some minor differences in the design output。

【讨论】:

    【解决方案2】:

    无需更改 API

    无法解析资源@string/faq_customer_service

    或

    无法解析资源@id/visible

    或

    无法解析资源@id/masked

    解决方案是,如果你实现TextInputLayout,可能会出现上述问题......所以只需将这些id或字符串添加到xml文件中作为它们的属性。

    【讨论】:

    • 我不明白
    【解决方案3】:

    这与渲染问题窗口有关

    如何解决:将这些值添加到任何值文件(文件名似乎无关紧要,我使用ids.xml,您也可以使用现有的,例如colors.xml 或strings.xml)

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <item name="visible" type="id"/>
        <item name="masked" type="id"/>
    </resources>
    

    【讨论】:

    • 完美!在res.values包下创建ids.xml文件,内容如上
    • 是的,这行得通。我认为这会在原始错误解决后引起问题,因此我建议保持警惕。
    • 我没有创建任何其他 xml 文件,而是将这些行添加到 strings.xml。
    • @Prabs,是的,资源文件的名字无所谓,在哪里也可以加colors.xml
    • @Shujito 是的,它有效。请回答它为什么起作用以及导致此错误的问题是什么。
    【解决方案4】:

    在strings.xml文件中添加标签下面的值:

     <item name="visible" type="id"/>
     <item name="masked" type="id"/>
    

    【讨论】:

      猜你喜欢
      • 2018-12-27
      • 2020-07-19
      • 2019-03-06
      • 1970-01-01
      • 1970-01-01
      • 2015-04-30
      • 1970-01-01
      • 1970-01-01
      • 2014-09-05
      相关资源
      最近更新 更多