如何开始与材料设计

如何开始与材料设计

问题描述:

我想创造一个美好的布局,我发现了一个例子,但它不工作:如何开始与材料设计

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_login" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="56dp" 
    android:paddingLeft="24dp" 
    android:paddingRight="24dp" 
    tools:context=".LoginActivity" 
    android:orientation="vertical"> 

    <ImageView 
     android:src="@drawable/logo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginBottom="24dp"/> 

    <!-- Email Label --> 
    <android.support.design.widget.TextInputLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="8dp" 
     android:layout_marginBottom="8dp"> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="textEmailAddress" 
      android:id="@+id/et_email" 
      android:hint="@string/email_str" /> 
    </android.support.design.widget.TextInputLayout> 

    <!-- Password Label --> 
    <android.support.design.widget.TextInputLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="8dp" 
     android:layout_marginBottom="8dp"> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="textPassword" 
      android:id="@+id/et_contraseña" 
      android:hint="@string/contraseña_str" /> 
    </android.support.design.widget.TextInputLayout> 



    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

     <android.support.v7.widget.AppCompatButton 
      android:id="@+id/but_iniciar_sesion" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="24dp" 
      android:layout_marginBottom="24dp" 
      android:padding="12dp" 
      android:text="@string/iniciar_sesion_str"/> 

     <android.support.v7.widget.AppCompatButton 
      android:id="@+id/but_crear_cuenta" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="24dp" 
      android:layout_marginBottom="24dp" 
      android:padding="12dp" 
      android:text="@string/crear_cuenta_str"/> 

    </LinearLayout> 

</LinearLayout> 

这是给我这个消息的错误:

android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class android.support.design.widget.TextInputLayout 

当然,我必须导入一个库或类似的东西。 也许在gradle或AndroidManifest.xml中添加一些行

有谁知道该怎么做?

尝试添加这种依赖关系到你的本地gradle这个

dependencies { 
    compile "com.android.support:appcompat-v7:25.1.0" 
    compile "com.android.support:design:25.1.0" 
} 

否则,如果日子会把你有麻烦“错误膨胀..”尝试清理和重建项目。 P.S.使用这些布局应延长AppCompatActivity而不是活动

+0

我做到了,而且我仍然收到相同的错误消息。不管怎么说,还是要谢谢你! – Sergio

+0

@Sergio嗯,我在android:id和android:hint中看到一个有趣的符号,试着重命名它们 –

随着有关添加依赖上面的回答活动,我beleive还必须使用设置在TextInputLayouts主题:

android:theme="@style/Theme.AppCompat" 

下面是使用的例子您的代码:

<!-- Email Label --> 
<android.support.design.widget.TextInputLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="8dp" 
    android:layout_marginBottom="8dp" 
    android:theme="@style/Theme.AppCompat"> 
    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="textEmailAddress" 
     android:id="@+id/et_email" 
     android:hint="@string/email_str" /> 
</android.support.design.widget.TextInputLayout>