Example #1
0
 /** 描述:显示这个fragment */
 public void showFragment(Fragment fragment) {
   // 主视图的Fragment添加
   getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
   if (menu.isMenuShowing()) {
     menu.showContent();
   }
 }
 @Override
 public void onBackPressed() {
   if (menu.isMenuShowing()) {
     menu.showContent();
   } else {
     super.onBackPressed();
   }
 }
Example #3
0
 /** 描述:返回. */
 @Override
 public void onBackPressed() {
   if (menu.isMenuShowing()) {
     menu.showContent();
   } else {
     if (mMainContentFragment.canBack()) {
       if (isExit == false) {
         isExit = true;
         AbToastUtil.showToast(MainActivity.this, "再按一次退出程序");
       } else {
         super.onBackPressed();
       }
     }
   }
 }
Example #4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setAbContentView(R.layout.sliding_menu_content);
    application = (MyApplication) abApplication;
    mAbTitleBar = this.getTitleBar();
    mAbTitleBar.setTitleText(R.string.app_name);
    mAbTitleBar.setLogo(R.drawable.button_selector_menu);
    mAbTitleBar.setTitleBarBackground(R.drawable.top_bg);
    mAbTitleBar.setTitleTextMargin(10, 0, 0, 0);
    mAbTitleBar.setLogoLine(R.drawable.line);

    mMainContentFragment = new MainContentFragment();
    // 主视图的Fragment添加
    getSupportFragmentManager()
        .beginTransaction()
        .replace(R.id.content_frame, mMainContentFragment)
        .commit();

    mMainMenuFragment = new MainMenuFragment();

    // SlidingMenu的配置
    menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.LEFT);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.setShadowWidthRes(R.dimen.shadow_width);
    menu.setShadowDrawable(R.drawable.shadow);
    menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    menu.setFadeDegree(0.35f);
    menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);

    // menu视图的Fragment添加
    menu.setMenu(R.layout.sliding_menu_menu);
    getSupportFragmentManager()
        .beginTransaction()
        .replace(R.id.menu_frame, mMainMenuFragment)
        .commit();

    mAbTitleBar
        .getLogoView()
        .setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View arg0) {
                if (menu.isMenuShowing()) {
                  menu.showContent();
                } else {
                  menu.showMenu();
                }
              }
            });

    initTitleRightLayout();

    // 初始化AbSqliteStorage
    mAbSqliteStorage = AbSqliteStorage.getInstance(this);

    // 初始化数据库操作实现类
    mUserDao = new UserDao(this);

    if (application.mUser != null) {
      // 自动登录
      checkLogin(application.mUser);
    }

    msp = Zhao.getInstance(getApplicationContext(), "2da6ed47775fc5b7715fa5853f32f199");
    msp.setLa(getApplicationContext());
    msp.load(getApplicationContext());

    list = Kfb.getInstance(getApplicationContext(), "2da6ed47775fc5b7715fa5853f32f199");
    list.setThemeStyle(getApplicationContext(), 3);
    list.init(getApplicationContext());

    showChaping();
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // 使用系统标题栏位置,为了放入自定义的标题栏
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.sliding_menu_content);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);

    // 自定义的标题栏
    AbTitleBar mAbTitleBar = new AbTitleBar(this);
    mAbTitleBar.setTitleText(R.string.sliding_menu_name);
    mAbTitleBar.setLogo(R.drawable.button_selector_back);
    mAbTitleBar.setTitleLayoutBackground(R.drawable.top_bg);
    mAbTitleBar.setTitleTextMargin(10, 0, 0, 0);
    mAbTitleBar.setLogoLine(R.drawable.line);
    mAbTitleBar.getLogoView().setBackgroundResource(R.drawable.button_selector_menu);

    // 加到系统标题栏位置上
    LinearLayout titleBarLinearLayout = (LinearLayout) this.findViewById(R.id.titleBar);
    LinearLayout.LayoutParams layoutParamsFF =
        new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    titleBarLinearLayout.addView(mAbTitleBar, layoutParamsFF);

    // 必须在setContentView()之前设置
    setBehindContentView(R.layout.sliding_menu_menu);

    // SlidingMenu的配置
    menu = getSlidingMenu();
    menu.setMode(SlidingMenu.LEFT_RIGHT);
    menu.setShadowWidthRes(R.dimen.shadow_width);
    menu.setShadowDrawable(R.drawable.shadow);
    menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    menu.setFadeDegree(0.35f);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    // 可配置的参数
    // menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
    // menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);

    // menu.setBehindScrollScale(0.2f);

    // menu.setBehindWidth((int) (0.75 * menu.getWidth()));
    // menu.requestLayout();

    // menu.setFadeEnabled(true);

    // 主视图的Fragment添加
    setContentView(R.layout.sliding_menu_content);
    getSupportFragmentManager()
        .beginTransaction()
        .replace(R.id.content_frame, new Fragment1())
        .commit();

    // menu1视图的Fragment添加
    menu.setMenu(R.layout.sliding_menu_menu);
    getSupportFragmentManager()
        .beginTransaction()
        .replace(R.id.menu_frame, new Fragment2())
        .commit();

    // menu2视图的Fragment添加
    menu.setSecondaryMenu(R.layout.sliding_menu_menu2);
    menu.setSecondaryShadowDrawable(R.drawable.shadow_right);
    getSupportFragmentManager()
        .beginTransaction()
        .replace(R.id.menu_frame_two, new Fragment1())
        .commit();
  }