문제

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?

도움이 되었습니까?

해결책

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);
}

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top