美文网首页Material Design专题
Design之TextInputEditText

Design之TextInputEditText

作者: Y小圆脸 | 来源:发表于2017-06-28 16:00 被阅读260次
属性 说明
app:Theme 设置下划线或其他的颜色属性
android.support.design:counterEnabled 是否显示计数器
android.support.design:counterMaxLength 设置计数器的最大值,与counterEnabled同时使用
android.support.design:counterTextAppearance 计数器的字体样式
android.support.design:counterOverflowTextAppearance 输入字符大于我们限定个数字符时的字体样式
android.support.design:errorEnabled 是否显示错误信息
android.support.design:errorTextAppearance 错误信息的字体样式
android.support.design:hintAnimationEnabled 是否显示hint的动画,默认true
android.support.design:hintEnabled 是否使用hint属性,默认true
android.support.design:hintTextAppearance 设置hint的文字样式(指运行动画效果之后的样式)
android.support.design:passwordToggleDrawable 设置密码开关Drawable图片,于passwordToggleEnabled同时使用
android.support.design:passwordToggleEnabled 是否显示密码开关图片,需要EditText设置inputType
android.support.design:passwordToggleTint 设置密码开关图片颜色
android.support.design:passwordToggleTintMode 设置密码开关图片(混合颜色模式),与passwordToggleTint同时使用

使用TextInputLayout

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.a070.demo.EditTextFragment">

    <LinearLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingLeft="15dp"
        android:paddingRight="15dp">

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            app:counterEnabled="true"
            app:counterMaxLength="20"
            app:counterTextAppearance="?android:attr/textAppearanceLarge"
            app:errorEnabled="true"
            app:errorTextAppearance="?android:attr/textAppearanceSmall"
            app:hintAnimationEnabled="true"
            app:hintTextAppearance="@style/hintAppearance"
            app:theme="@style/TextInputLayoutLineColor">

            <android.support.design.widget.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="请输入用户名"
                android:textColor="#333333"
                android:textColorHint="#999999"
                android:textSize="14dp" />


        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            app:counterEnabled="true"
            app:counterMaxLength="20"
            app:counterTextAppearance="?android:attr/textAppearanceMedium"
            app:errorEnabled="true"
            app:errorTextAppearance="?android:attr/textAppearanceSmall"
            app:hintAnimationEnabled="true"
            app:hintTextAppearance="@style/hintAppearance"
            app:passwordToggleDrawable="@drawable/cb_eye_selector"
            app:passwordToggleEnabled="true"
            app:passwordToggleTint="@color/colorPrimary"
            app:passwordToggleTintMode="multiply"
            app:theme="@style/TextInputLayoutLineColor">

            <android.support.design.widget.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="请输入用户名"
                android:inputType="textPassword"
                android:textColor="#333333"
                android:textColorHint="#999999"
                android:textSize="14dp" />


        </android.support.design.widget.TextInputLayout>


    </LinearLayout>

</FrameLayout>

在style中输入样式

 <!--EditText的主題 Start-->
<style name="TextInputLayoutLineColor" parent="Theme.AppCompat.Light">
    <!--没有获取焦点时的颜色-->
    <item name="colorControlNormal">@color/colorAccent</item>
    <!--获取焦点时的颜色-->
    <item name="colorControlActivated">@color/main_color</item>
</style>

<!--浮动标签-->
<style name="hintAppearance" parent="TextAppearance.AppCompat">
    <item name="android:textSize">14sp</item>
    <item name="android:textColor">@color/colorPrimary</item>
</style>

<!--错误提示信息-->
<style name="errorAppearance" parent="TextAppearance.AppCompat">
    <item name="android:textSize">14sp</item>
    <item name="android:textColor">@android:color/holo_red_light</item>
</style>

<!--超出计数最大长度,浮动标签,下划线,计数文字都会改变颜色-->
<style name="counterOverflowTextAppearance" parent="TextAppearance.AppCompat">
    <item name="android:textSize">14sp</item>
    <item name="android:textColor">@android:color/holo_red_dark</item>
</style>

相关文章

网友评论

    本文标题:Design之TextInputEditText

    本文链接:https://www.haomeiwen.com/subject/uwvucxtx.html