我正在尝试实现一个fab动作,当它一旦点击就会启动一个片段并再次触摸时会关闭片段。我怎么能这样做。
这是我的代码:
final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
/*Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();*/
NewOrdersFragment newOrdersFragment = new NewOrdersFragment();
if(isOpen){
fab.startAnimation(FabRanticlockwise);
FragmentManager orderManager = getSupportFragmentManager();
orderManager.beginTransaction().remove(newOrdersFragment);
isOpen = false;
}
else{
fab.startAnimation(FabRClockwise);
FragmentManager orderManager = getSupportFragmentManager();
orderManager.beginTransaction().replace(R.id.content_buyer_main_area, newOrdersFragment).commit();
isOpen = true;
}
}
});
答案 0 :(得分:0)
list()
或
beginTransaction().remove(yourFragment)
对你的情况很方便。