0

我有ImageButton一个EditText可见的:

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

    }
});

ImageButton单击EditText从右向左滑入时,当ImageButton再次单击EditText时应再次滑出并隐藏它,我该如何创建这种效果?

4

2 回答 2

4

您可以通过检查EditText是否可见来做到这一点:

if(mySearchView.getVisibility() == View.VISIBLE){
    mySearchView.setVisibility(View.GONE);
} else {
    mySearchView.setVisibility(View.VISIBLE);
}
于 2014-05-01T16:59:54.733 回答
1

您可以像这样使用 ToggleButton

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

并将图像设置为切换按钮的背景

于 2014-05-01T17:02:31.340 回答