Android: How to place an animated image inside an EditText that we can show and hide

后端 未结 4 1661
时光说笑
时光说笑 2021-01-06 07:25

I am trying to add an animated spinner inside a EditText view to the right. And programmatically show/hide it.

I have created the animated spinner b

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-06 08:01

    If you are using TextInputLayout and want to animate the drawable look into this

    First define the animation set like this way in res/anim/

    
    
        
        
    
    
    

    and in your code set the animation

    final Animation animation = AnimationUtils.loadAnimation(this, R.anim.anims);
            final ImageView imgLeft = (ImageView) findViewById(R.id.imgLeft);
    
            final EditText et = (EditText) findViewById(R.id.cardnumEditTexst);
            et.setOnFocusChangeListener(new View.OnFocusChangeListener()
            {
                @Override
                public void onFocusChange(View v, boolean hasFocus)
                {
                    if (hasFocus)
                    {
                        if (et.getText().length() == 0)
                        {
                            imgLeft.startAnimation(animation);
                        }
                    } else
                    {
                        if (et.getText().length() == 0)
                            imgLeft.clearAnimation();
                    }
                }
            });
    

提交回复
热议问题