1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.support.design.widget; 18 19 import com.example.android.support.design.R; 20 21 import android.os.Bundle; 22 import android.support.design.widget.TextInputLayout; 23 import android.support.v7.app.AppCompatActivity; 24 import android.view.View; 25 26 /** 27 * This demonstrates idiomatic usage of {@code TextInputLayout} 28 */ 29 public class TextInputLayoutUsage extends AppCompatActivity { 30 31 private TextInputLayout mUsernameInputLayout; 32 private TextInputLayout mPasswordInputLayout; 33 34 @Override 35 protected void onCreate(Bundle savedInstanceState) { 36 super.onCreate(savedInstanceState); 37 setContentView(R.layout.design_text_input); 38 39 mUsernameInputLayout = (TextInputLayout) findViewById(R.id.input_username); 40 mPasswordInputLayout = (TextInputLayout) findViewById(R.id.input_password); 41 } 42 43 public void showError(View view) { 44 mUsernameInputLayout.setError("Some unknown error has occurred"); 45 } 46 47 public void clearError(View view) { 48 mUsernameInputLayout.setError(null); 49 } 50 51 public void setPasswordEnabled(View view) { 52 mPasswordInputLayout.setPasswordVisibilityToggleEnabled(true); 53 } 54 55 public void setPasswordDisabled(View view) { 56 mPasswordInputLayout.setPasswordVisibilityToggleEnabled(false); 57 } 58 59 public void toggleEnabled(View view) { 60 mUsernameInputLayout.setEnabled(!mUsernameInputLayout.isEnabled()); 61 } 62 63 } 64