【问题标题】:Xamarin Android Support Design Library Not AvailableXamarin Android 支持设计库不可用
【发布时间】:2017-01-18 20:37:34
【问题描述】:

我在 Visual Studio 中使用 NuGet 添加了 Xamarin Android 支持设计库(及其所有依赖项),但是当我在 AXML 代码中使用组件时,它说它是无效的子元素。从我能找到的所有文档和示例中,除了通过 NuGet 添加包之外,似乎不需要做任何额外的事情。我可以在解决方案资源管理器的 References 文件夹中看到所有库。

我确定我遗漏了一些非常简单的东西,但我找不到问题所在。任何帮助,将不胜感激。谢谢!

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

   <ImageView
        p1:src="@drawable/boxlogo"
        p1:layout_width="match_parent"
        p1:layout_height="wrap_content"
        p1:id="@+id/boxLogo" />
    <android.support.design.widget.TextInputLayout
       p1:layout_width="match_parent"
       p1:layout_height="wrap_content">
       <EditText
           p1:layout_width="match_parent"
           p1:layout_height="wrap_content"
           p1:id="@+id/sku"
           p1:hint="@string/sku" />
    </android.support.design.widget.TextInputLayout>
...
</LinearLayout>

我收到android.support.design.widget.TextInputLayout标签上的错误

我能够访问我的 C# 代码中的库。

【问题讨论】:

  • 什么错误?也许您应该使用TextInputEditText 而不是 EditText?
  • "元素 'LinearLayout' 的子元素 'android.support.design.widget.TextInputLayout'" 是我得到的错误,我认为这与 Alex 得到的错误相同。 Xamarin 博客给出了带有 'EditText' (blog.xamarin.com/…) 的示例,但即使使用 'android.support.design.widget.TextInputEditText' 它也不起作用。

标签: android xml visual-studio xamarin xamarin.android


【解决方案1】:

查看TextInputLayout 的文档: https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html

上面写着:

提供 TextInputEditText 类用作此布局的子级。使用 TextInputEditText 允许 TextInputLayout 更好地控制任何文本输入的视觉方面。示例用法如下:

<android.support.design.widget.TextInputLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content">

     <android.support.design.widget.TextInputEditText
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:hint="@string/form_username"/>

</android.support.design.widget.TextInputLayout>

看来您需要使用支持库中的EditText,例如android.support.design.widget.TextInputEditText

【讨论】:

  • Alex 没有写出确切的错误消息,但从描述中我认为他得到的和我得到的一样:“元素 'LinearLayout' 具有无效的子元素 'android.support.design.widget。文本输入布局'"。我正在使用 TextInputEditText 并没有什么不同。
猜你喜欢
  • 2015-08-24
  • 1970-01-01
  • 2016-03-22
  • 1970-01-01
  • 2015-09-04
  • 1970-01-01
  • 1970-01-01
  • 2015-08-26
  • 1970-01-01
相关资源
最近更新 更多