Android 如何从材料设计开始

Android 如何从材料设计开始,android,layout,material-design,android-textinputlayout,Android,Layout,Material Design,Android Textinputlayout,我正在尝试创建一个漂亮的布局,我找到了一个示例,但它不起作用: <?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" andro

我正在尝试创建一个漂亮的布局,我找到了一个示例,但它不起作用:

<?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>
当然,我必须导入一个库或类似的东西。 可能在gradle或AndroidManifest.xml中添加一些行


有人知道怎么做吗?

尝试将此依赖项添加到本地gradle

dependencies {
    compile "com.android.support:appcompat-v7:25.1.0"
    compile "com.android.support:design:25.1.0"
}
否则,若您遇到“错误膨胀…”问题,请尝试清理并重建项目。
使用这些布局的PS活动应该扩展AppCompatActivity,而不是Activity

尝试将此依赖项添加到本地gradle

dependencies {
    compile "com.android.support:appcompat-v7:25.1.0"
    compile "com.android.support:design:25.1.0"
}
否则,若您遇到“错误膨胀…”问题,请尝试清理并重建项目。
P.S.使用这些布局的活动应该扩展AppCompatActivity而不是Activity

以及上面关于添加依赖项的答案,我相信您还必须使用以下方法在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>

除了上面关于添加依赖项的回答之外,我相信您还必须使用以下方法在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>


我这样做了,但仍然收到相同的错误消息。无论如何谢谢你@Sergio嗯,我在android中看到了一个有趣的符号:id和android:hint,尝试重命名它们。我这么做了,但仍然收到相同的错误消息。无论如何谢谢你@Sergio嗯,我在android中看到一个有趣的符号:id和android:hint,试着重命名它们