标签:checkBox 示例 editText private 密码 CheckBox Android 隐藏
在Android开发中,需要密码的隐藏和显示,下面就和大家分享一下使用方法:
xml代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/white"
android:orientation="horizontal"
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="新密码"
android:textColor="@color/black"
android:textSize="18dp"
android:gravity="center_vertical"
android:layout_marginLeft="15dp"/
<EditText
android:id="@+id/newpassword"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:inputType="textPassword"
android:hint="请设置登录密码"
android:background="@null"/
<CheckBox
android:id="@+id/CheckBox"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="15dp"
android:textSize="16dp"
android:text="显示"
/
</LinearLayout
隐藏图标代码
android:button="@null"
JAVA代码:
/**
* Created by fby on 2017/9/11.
*/
public class ChargepsdActivity extends Activity {
private EditText editText;
private CheckBox checkBox;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chargepsd);
editText = (EditText) findViewById(R.id.newpassword);
checkBox = (CheckBox) findViewById(R.id.CheckBox);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
//如果选中,显示密码
editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}else{
//否则隐藏密码
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
});
}
}
效果展示:
以上就是本文的全部内容,希望对大家的学习有所帮助。更多教程请访问码农之家
标签:checkBox,示例,editText,private,密码,CheckBox,Android,隐藏 来源: https://www.cnblogs.com/myhomepages/p/16527504.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。