我有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
应再次滑出,并隐藏它,我怎么能创造这种效果?
答案 0 :(得分:3)
您可以通过检查EditText
是否可见来执行此操作:
if(mySearchView.getVisibility() == View.VISIBLE){
mySearchView.setVisibility(View.GONE);
} else {
mySearchView.setVisibility(View.VISIBLE);
}
答案 1 :(得分: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
}
});
并将图像设置为togglebuttons的背景