1.Android support design TextInputLayout

1.Android support design TextInputLayout

  • Android support design TextInputLayout
    • TextInputLayout效果
    • gradle配置
    • TextInputLayout布局设置
    • TextInputLayout主题颜色
    • TextInputLayout错误提示

TextInputLayout效果

1.Android support design TextInputLayout_第1张图片

gradle配置

compile 'com.android.support:design:23.0.1' 或者更高版本

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
}

TextInputLayout布局设置

<android.support.design.widget.TextInputLayout
    android:id="@+id/email_text_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
         android:id="@+id/email"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:hint="@string/prompt_email"
         android:inputType="textEmailAddress"
         android:maxLines="1"
         android:singleLine="true" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
         android:id="@+id/password_text_input_layout"
         android:layout_width="match_parent"
         android:layout_height="wrap_content">

    <EditText
         android:id="@+id/password"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:hint="@string/prompt_password"
         android:imeActionId="@+id/login"
         android:imeActionLabel="@string/action_sign_in_short"
         android:imeOptions="actionUnspecified"
         android:inputType="textPassword"
         android:maxLines="1"
         android:singleLine="true" />
</android.support.design.widget.TextInputLayout>

TextInputLayout主题颜色

TextInputLayout主题颜色在style.xml里面的AppTheme上配置。

主要有colorAccent就行。

<item name="colorAccent">@color/colorAccent</item>

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColorPrimary">@color/textPrimary</item>
    <item name="android:textColorHint">@color/textHint</item>
</style>

TextInputLayout错误提示

TextInputLayout错误提示的设置与两个方法有关:
- TextInputLayout.setErrorEnabled(boolean enabled)
- TextInputLayout.setError(CharSequence error)

也不难理解,一个是这是可见,一个是设置错误提示内容,可以结合自己的需求而定。

你可能感兴趣的:(android,gradle,desgin,support,TextInputL)