zoukankan      html  css  js  c++  java
  • Android Design TextinputLayout

    使用该布局 需要在build.gradle中的dependencies块中添加两个依赖来向下兼容

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.1.0'
        compile 'com.android.support:design:23.1.0'
    }
    <LinearLayout 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"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="com.example.alan.blogs.LoginActivity"
        tools:showIn="@layout/activity_login"
        android:orientation="vertical">
    
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/email_TextInputLayout"
            android:layout_marginTop="32dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            >
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:hint="@string/emailHint"
                android:ems="10"
                android:id="@+id/edit_email" />
           </android.support.design.widget.TextInputLayout>
    
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/password_TextInputLayout">
            <EditText
                android:inputType="textPassword"
                android:id="@+id/edit_password"
                android:hint="@string/passwordHint"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />
        </android.support.design.widget.TextInputLayout>
        <Button
            android:layout_marginTop="16dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:text="@string/login"
            android:textColor="@color/white"
            android:background="@xml/ripple"
            />
    </LinearLayout>
    public void init(){
            this.emailInputLayout=(TextInputLayout)findViewById(R.id.email_TextInputLayout);
            this.passwordInputLayout=(TextInputLayout)findViewById(R.id.password_TextInputLayout);
           
            final EditText emailEditText=emailInputLayout.getEditText();
            EditText passwordEditText=passwordInputLayout.getEditText();
    //        emailInputLayout.setHint("请输入Email");
    //        passwordInputLayout.setHint("输入密码");                //也可以在editText中设置Hint InputLayput会自动获取该Hint
            emailEditText.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
                }
    
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
    
                }
    
                @Override
                public void afterTextChanged(Editable s) {
                    if(emailEditText.getText().toString().contains("@")==false){                    emailInputLayout.setErrorEnabled(true);                      emailInputLayout.setError("请输入正确的Email地址");                }else {
                        emailInputLayout.setErrorEnabled(false);
                    }
                }
            });
        }
  • 相关阅读:
    【原创】InstallSheild使用问题笔记卸载程序之后重新启动,总是报错找不到文件?
    【学习】关于绩效管理的知识
    【原创】Asp.net MVC学习笔记之基于类型来绑定Model的属性
    【学习】如何进行绩效面谈
    【原创】【续】InstallSheild使用问题笔记卸载程序之后重新启动,总是报错找不到文件?
    SharePoint 2010 学习资料索引与注解(2)
    一张很厉害的图
    SharePoint 2010 学习资料索引与注解(1)
    StackOverflow 并不只是一个问答网站
    最近花了点儿时间看书学习
  • 原文地址:https://www.cnblogs.com/zzw1994/p/5238955.html
Copyright © 2011-2022 走看看