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?
这篇关于如何使用自定义图像编辑文本密码,如轴银行应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用自定义图像编辑文本密码,如轴银行应
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01