搭建直播平台,显示隐藏密码,眼睛特效
搭建直播平台,显示隐藏密码,眼睛特效
package com.example.test2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private EditText password;
private ImageView imageView;
private boolean flag=true;
private HideReturnsTransformationMethod method_show;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
password = findViewById(R.id.password);
imageView = findViewById(R.id.img);
imageView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.img:
changeImage();
}
}
private void changeImage() {
// todo 每次进入登陆时输入的密码都是隐藏的
PasswordTransformationMethod methodHide=PasswordTransformationMethod.getInstance();
password.setTransformationMethod(methodHide);
if(flag){
imageView.setImageDrawable(this.getResources().getDrawable(R.drawable.eye1));
flag=false;
// todo 隐藏密码
PasswordTransformationMethod method_hide = PasswordTransformationMethod.getInstance();
password.setTransformationMethod(method_hide);
}
else{
imageView.setImageDrawable(this.getResources().getDrawable(R.drawable.eye2));
flag=true;
// todo 显示密码
method_show= HideReturnsTransformationMethod.getInstance();
password.setTransformationMethod(method_show);
}
if (!password.getText().toString().trim().equals("")) {
password.setSelection(password.getText().toString().trim().length());//将光标移至文字末尾
}
}
}
以上就是 搭建直播平台,显示隐藏密码,眼睛特效,更多内容欢迎关注之后的文章