这是一个简单的登录界面,主要有2个效果 1 登陆背景的图片交替渐变,2 密码点击实现隐藏和显示
1 主要代码:密码点击实现隐藏和显示
1 public static int flag = 0;//定义按钮多次点击
2按钮添加事件,点击按钮。if判断是否点击密码显示按钮
2 showpwd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (flag == 0) { //默认设置为密文 LoginActivity.this.userpwd.setTransformationMethod (PasswordTransformationMethod.getInstance()); flag = 1; } else {//切换成明文 LoginActivity.this.userpwd.setTransformationMethod (HideReturnsTransformationMethod.getInstance()); flag = 0; } } });2 这个功能的代码量比较大,而且涉及到背景图片,我这里值贴出代码,如有需要请和我联系,(另外此功能也是在网上看到的,链接丢了,自己可以找找看,还有demo作者看到后,请不要生气,无意冒犯,只是为了新手更好更快的适应开发)
private void initViews() {//初始化背景图片 mImageView1 = (ImageView) findViewById(R.id.image1); mImageView2 = (ImageView) findViewById(R.id.image2); mImageView3 = (ImageView) findViewById(R.id.image3); } private void startAnimation() { ObjectAnimator anim1 = new ObjectAnimator().ofFloat(mImageView1, "alpha", 1f, 0f).setDuration(5000); ObjectAnimator anim2 = new ObjectAnimator().ofFloat(mImageView2, "alpha", 0f, 1f).setDuration(5000); AnimatorSet set = new AnimatorSet(); set.playTogether(anim1, anim2); ObjectAnimator anim3 = new ObjectAnimator().ofFloat(mImageView2, "alpha", 1f, 0f).setDuration(5000); ObjectAnimator anim4 = new ObjectAnimator().ofFloat(mImageView3, "alpha", 0f, 1f).setDuration(5000); AnimatorSet set1 = new AnimatorSet(); set1.playTogether(anim3, anim4); ObjectAnimator anim5 = new ObjectAnimator().ofFloat(mImageView3, "alpha", 1f, 0f).setDuration(5000); ObjectAnimator anim6 = new ObjectAnimator().ofFloat(mImageView1, "alpha", 0f, 1f).setDuration(5000); AnimatorSet set2 = new AnimatorSet(); set2.playTogether(anim5, anim6); AnimatorSet set3 = new AnimatorSet(); set3.playSequentially(set, set1, set2); set3.addListener(new AnimatorListenerAdapter() { private boolean mCanceled; @Override public void onAnimationStart(Animator animation) { mCanceled = false; } @Override public void onAnimationCancel(Animator animation) { mCanceled = true; } @Override public void onAnimationEnd(Animator animation) { if (!mCanceled) { animation.start(); } } }); set3.start(); }