How to use custom image for edittext password like axis bank app(如何使用自定义图像编辑文本密码,如轴银行应用程序)
问题描述
如何在edittext密码字段中使用自定义图像而不是'*'?
看图:
任何答案或提示将不胜感激.
答案来自.
公共类 MyPasswordTransformationMethod 扩展 PasswordTransformationMethod {@覆盖public CharSequence getTransformation(CharSequence source, View view) {return new PasswordCharSequence(source);}私有类 PasswordCharSequence 实现 CharSequence {私人 CharSequence mSource;公共密码字符序列(字符序列源){mSource = 来源;//存储字符序列}公共 char charAt(int index) {返回 '';//这是重要的部分}公共整数长度(){返回 mSource.length();//返回默认值}公共 CharSequence subSequence(int start, int end) {返回 mSource.subSequence(开始,结束);//返回默认值}}};参考:在android中如何在输入类型为textPassword的EditText中显示星号(*)代替点?
How to use custom image instead of '*' in edittext password field?
see image:
Any answer or hint will be greatly appreciated.
The answer comes from this tutorial and it covers a behaviour when a user:
enters into the login screen, keyboard will open automatically.
tries to enter value in it then textbox background changes to textbox with star background.
tries to cancel/delete the input value by using back key on keyboard then textbox background will change to textbox without star background.
First of all you have to create two drawables:
Then, according to this approach, you have to implement addTextChangedListener method on your EditText. After that, as a parameter, you create a new instance of a TextWatcher class and you implement its methods:
etxtPin1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
if(etxtPin1.getText().toString().trim().length()==1){
etxtPin1.clearFocus();
etxtPin2.requestFocus();
etxtPin1.setBackgroundResource(R.drawable.pin_txt_bg_star);
}
}
});
Then, you have to implement setOnKeyListener and its method onKey:
this.etxtPin1.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View paramView, int paramInt, KeyEvent paramKeyEvent) {
if ((paramKeyEvent.getAction() == KeyEvent.ACTION_DOWN)&&(paramInt == 67) && (LoginActivity.this.etxtPin2.getText().length() == 0)) {
etxtPin1.requestFocus();
etxtPin1.setBackgroundResource(R.drawable.pin_txt_bg);
etxtPin1.setText("");
}
return false;
}
});
Another approach: create you own class which extends PasswordTransformationMethod.
public class MyPasswordTransformationMethod extends PasswordTransformationMethod {
@Override
public CharSequence getTransformation(CharSequence source, View view) {
return new PasswordCharSequence(source);
}
private class PasswordCharSequence implements CharSequence {
private CharSequence mSource;
public PasswordCharSequence(CharSequence source) {
mSource = source; // Store char sequence
}
public char charAt(int index) {
return '*'; // This is the important part
}
public int length() {
return mSource.length(); // Return default
}
public CharSequence subSequence(int start, int end) {
return mSource.subSequence(start, end); // Return default
}
}
};
Reference: In android how to show asterisk (*) in place of dots in EditText having inputtype as textPassword?
这篇关于如何使用自定义图像编辑文本密码,如轴银行应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用自定义图像编辑文本密码,如轴银行应
基础教程推荐
- 我的 UIImageView 的任务 2022-01-01
- 在 Android 模拟器中激活网络位置提供程序? 2022-01-01
- 突出显示朗读文本(在 iPhone 的故事书类型应用程序中) 2022-01-01
- 在 appComponent dagger 2 中动态添加测试模块? 2022-01-01
- 可可/目标C(OSX不是iOS)从子对象访问父对象 2022-01-01
- Android:STATE_SELECTED不工作 2022-01-01
- - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view 如何工作 2022-01-01
- 如何将多个组件添加到 PickerView? 2022-01-01
- 新的@SystemApi 注解是什么意思,和@hide 有什么区别 2022-01-01
- 在 iOS8 中无法获得正确的键盘高度值 2022-01-01
