jeudi 4 janvier 2018

Edit text expand on click

I have a edittext that needs to expand to the full width of the app when typing, when clicked outside or anywhere else it goes back to regular size. i have found a piece of code that does work for what i want but it doesn't hold such as it reverses the process once the end of the code has run. Im looking for a way around this.Or another way to do this, a similar example to this is when using a web browser on a mobile device, when typing a url or search term the url bar expands to full width.

code .java file

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.EditText;

 public class Home extends AppCompatActivity {

public EditText search_bar;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);


   search_bar = (EditText) findViewById(R.id.search_bar);

}
    public void edit_clicked(View view){

    Animation scaleAnimation = new ScaleAnimation(0, 2, 1, 2);
    scaleAnimation.setDuration(750);
    search_bar.startAnimation(scaleAnimation);


}

}




Aucun commentaire:

Enregistrer un commentaire