2016-12-13 105 views
1

我想創造一個美好的佈局,我發現了一個例子,但它不工作:如何開始與材料設計

<?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中添加一些行

有誰知道該怎麼做?

回答

0

嘗試添加這種依賴關係到你的本地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中看到一個有趣的符號,試着重命名它們 –

0

隨着有關添加依賴上面的回答活動,我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>