android edittext show hide password
hello android developer in this tutorial, you’ll learn how to use edittext activity in android studio.EditText is used to get input from the user
XML (activity_main.xml)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<android.support.constraint.ConstraintLayout 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="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/lblPassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="32dp" android:text="Enter Password" android:textAppearance="?android:attr/textAppearanceLarge" app:layout_constraintBottom_toTopOf="@+id/password" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" app:layout_constraintTop_toBottomOf="@+id/lblPassword" tools:layout_editor_absoluteX="0dp"> <requestFocus /> </EditText> <Button android:id="@+id/btn5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Submit" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/password" /> </android.support.constraint.ConstraintLayout> |
JAVA (MainActivity.java)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class Password extends AppCompatActivity { private EditText password; private Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_password); addListenerOnButton(); } public void addListenerOnButton() { password = (EditText) findViewById(R.id.password); btn = (Button) findViewById(R.id.btn5); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(Password.this, password.getText(), Toast.LENGTH_SHORT).show(); } }); } } |