質問

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