如何关闭打开的片段并返回主要活动?
public class MainActivity extends SlidingFragmentActivity {
public SlidingMenu sm;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Main layout
setContentView(R.layout.activity_main);
setBehindContentView(R.layout.menu_frame);
// SlidingMenu
sm = getSlidingMenu();
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
sm.setBehindOffset(120);
sm.setMode(SlidingMenu.LEFT_RIGHT);
// Left menu
getSupportFragmentManager().beginTransaction()
.replace(R.id.menu_frame, new LeftMenuFragment()).commit();
// Right menu
getSlidingMenu().setSecondaryMenu(R.layout.menu_frame_second);
getSupportFragmentManager().beginTransaction()
.replace(R.id.menu_frame_two, new RightMenuFragment()).commit();
}
public class LeftMenuFragment extends Fragment{
ImageView img;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_left_menu, container,
false);
this.inflater = inflater;
img = (ImageView) view.findViewById(R.id.test);
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//RETURN TO MAIN ACTIVITY
}
});
}
return view;
}
是否可以创建垂直滑动?
答案 0 :(得分:0)
如果您只想关闭滑动菜单,请执行
if(sm.isMenuShowing()){
sm.toggle();
}