2017-01-18 247 views
0

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

我敢肯定我错过了一件非常简单的事情,但我找不到什么不对。任何帮助,将不胜感激。谢谢!

<?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#代码库标签上的错误。

+1

什么错误?可能你应该使用[TextInputEditText](https://developer.android.com/reference/android/support/design/widget/TextInputEditText.html)而不是EditText? –

+0

“元素'LinearLayout'具有无效的子元素'android.support.design.widget.TextInputLayout'”是我得到的错误,我认为这是Alex得到的错误。 Xamarin博客给出了'EditText'的示例(https://blog.xamarin.com/add-beautiful-material-design-with-the-android-support-design-library/),但即使在使用'android.support .design.widget.TextInputEditText'不起作用。 –

回答

0

检查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

+0

亚历克斯没有写出确切的错误信息,但从描述我认为他得到了相同的,我得到:“元素'LinearLayout'具有无效的子元素'android.support.design.widget.TextInputLayout'”。我使用TextInputEditText,它没有什么区别。 –