Question

I have this ImageButton that makes a EditText visible:

final ImageButton k = (ImageButton) findViewById(R.id.imageSearchButton);
k.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
        Animation anim = AnimationUtils.loadAnimation(CallActivity.this, R.anim.search_jump);
        k.startAnimation(anim);

        mySearchView = (EditText) findViewById(R.id.searchText);
        mySearchView.setVisibility(View.VISIBLE);
        Animation searchAnim = AnimationUtils.loadAnimation(CallActivity.this, R.anim.push_left_in);
        mySearchView.startAnimation(searchAnim);

    }
});

When the ImageButton is clicked the EditText slides in from right to left, and then when the ImageButton is clicked again the EditText should slide out again, and hiding it, how could i create this effect?

Was it helpful?

Solution

You can do this by checking that the EditText is visible or not:

if(mySearchView.getVisibility() == View.VISIBLE){
    mySearchView.setVisibility(View.GONE);
} else {
    mySearchView.setVisibility(View.VISIBLE);
}

OTHER TIPS

You can use ToggleButton like this

ToggleButton b = (ToggleButton) findViewById(R.id.myButton);

// attach an OnClickListener
b.setOnClickListener(new OnClickListener()
{
    if(((ToggleButton) view).isChecked()) {
    // handle toggle on
} else {
   // handle toggle off
} 
});

And set the images as background for togglebuttons

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top