简体   繁体   English

如何关闭导航抽屉

[英]How to close the navigation drawer

*Am working on an App where i have used an old navigation drawer pattern.My problem is when am pressing the back button,navigation drawer is coming out instead of the previous activity.I think am not closing the navigation drawer and i really don't know how to close the navigation drawer. *在一个使用旧导航抽屉模式的应用程序上工作。我的问题是按下返回按钮时,导航抽屉出现了,而不是先前的活动。我认为没有关闭导航抽屉,我确实没有不知道如何关闭导航抽屉。 So,please help me to get out of this.Thank You 因此,请帮助我摆脱困境。谢谢

         public class ReportProblem extends Activity {

    WebView mWebView;

 SimpleSideDrawer rightSlider;
LinearLayout ll_menu, ll_start_stop;
Context mContext = this;

private RelativeLayout rl_main;

private LoaderProgress loader;
Utillity utillity;

 private ImageView iv_browser;

 private CustomText tv_open_in_browser;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_report_problem);

utillity =  new Utillity(mContext);

ll_menu = (LinearLayout) findViewById(R.id.ll_menu);

rightSlider = new SimpleSideDrawer(this);

rightSlider.setLeftBehindContentView(R.layout.menu_drawer);

rl_main = (RelativeLayout) findViewById(R.id.rl_main);

  menuClick();
  ll_menu.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {

        rightSlider.toggleLeftDrawer();

    }
});

rl_main.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }
});

loader = new LoaderProgress(mContext);

mWebView = (WebView) findViewById(R.id.web_activity_summery);
mWebView.getSettings().setJavaScriptEnabled(true);


iv_browser=(ImageView)findViewById(R.id.iv_browser);

tv_open_in_browser=(CustomText)findViewById(R.id.tv_open_in_browser);

iv_browser.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if(v.getTag().toString().equals("0"))
        {
            v.setTag("1");
            tv_open_in_browser.setVisibility(View.VISIBLE);
        }
        else
        {
            v.setTag("0");
            tv_open_in_browser.setVisibility(View.GONE);
        }
    }
});


tv_open_in_browser.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

        String base64 = Base64.encodeToString(ParseUser.getCurrentUser()
                .getObjectId().toString().getBytes(), Base64.DEFAULT);

            Intent browserIntent = new Intent(Intent.ACTION_VIEW);
                browserIntent.setData(Uri.parse("http://.com/app/feedback/index.html?id="+URLEncoder.encode(base64)));
            startActivity(browserIntent);
            v.setTag("0");
            tv_open_in_browser.setVisibility(View.GONE);
    }
});


mWebView.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

        if(iv_browser.getTag().toString().equals("1"))
        {
            iv_browser.setTag("0");

            tv_open_in_browser.setVisibility(View.GONE);
        }

    }
});







if (utillity.isNetworkAvailable()) {

    String base64 = Base64.encodeToString(ParseUser.getCurrentUser()
            .getObjectId().toString().getBytes(), Base64.DEFAULT);
    mWebView.loadUrl("http://com/app/feedback/index.html?   id="+URLEncoder.encode(base64));

} else {

    showAlertDialog("Please make sure that you have an active Internet connection");
}

new GpsSharedPrefrence(mContext)
        .setActivityState(GpsSharedPrefrence.ActivityResume);

  }



  @Override
  protected void onResume() {
   // TODO Auto-generated method stub

   new GpsSharedPrefrence(mContext)
        .setActivityState(GpsSharedPrefrence.ActivityResume);

      super.onResume();
}

  @Override
 protected void onPause() {
new GpsSharedPrefrence(mContext)
        .setActivityState(GpsSharedPrefrence.ActivityPause);
super.onPause();
}

public void menuClick() {

View menuView = rightSlider.getLeftBehindView();

   LinearLayout ll_activity, ll_history, ll_configure_device, ll_settings,  ll_activity_summery, ll_logout;

 ll_activity = (LinearLayout) menuView.findViewById(R.id.ll_activity);
 ll_history = (LinearLayout) menuView.findViewById(R.id.ll_history);
 ll_configure_device = (LinearLayout) menuView
        .findViewById(R.id.ll_configure_device);
 ll_settings = (LinearLayout) menuView.findViewById(R.id.ll_settings);
 ll_activity_summery = (LinearLayout) menuView
        .findViewById(R.id.ll_activity_summery);
ll_logout = (LinearLayout) menuView.findViewById(R.id.ll_logout);
LinearLayout ll_report_problem = (LinearLayout)  menuView.findViewById(R.id.ll_report_problem);
     ll_report_problem.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {

        rightSlider.toggleLeftDrawer();

        // Intent intentActivity = new Intent(mContext,
        // Activities.class);
        // startActivity(intentActivity);
        // finish();
    }
});
LinearLayout ll_treadmill = (LinearLayout)    menuView.findViewById(R.id.ll_treadmill);


 ll_treadmill.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {


        Intent intentActivity = new Intent(mContext,
                TreadMillActivity.class);
        Bundle  animation=ActivityOptions.makeCustomAnimation(getApplicationContext(), 
                R.anim.animation, R.anim.animation2).toBundle();
        startActivity(intentActivity,animation);


    }
});

ll_activity.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {

        Intent intentActivity = new Intent(mContext, Activities.class);
        Bundle animation=ActivityOptions.makeCustomAnimation(getApplicationContext(),
                R.anim.animation, R.anim.animation2).toBundle();
        startActivity(intentActivity,animation);

    }
});
ll_history.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intentActivity = new Intent(mContext,
                HistoryActivity_web.class);
        Bundle animation=ActivityOptions.makeCustomAnimation(getApplicationContext(), 
                R.anim.animation, R.anim.animation2).toBundle();
        startActivity(intentActivity,animation);

    }
});
ll_configure_device.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intentActivity = new Intent(mContext,
                InsoleConnection.class);
        Bundle  animation=ActivityOptions.makeCustomAnimation(getApplicationContext(),
                R.anim.animation, R.anim.animation2).toBundle();
        startActivity(intentActivity,animation);

    }
});
ll_settings.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intentActivity = new Intent(mContext,
                SettingsActivity.class);
        Bundle animation=ActivityOptions.makeCustomAnimation(getApplicationContext(),
                R.anim.animation, R.anim.animation2).toBundle();
        startActivity(intentActivity,animation);

    }
});

ll_activity_summery.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intentActivity = new Intent(mContext,
                ActivitySummery.class);
        Bundle animation=ActivityOptions.makeCustomAnimation(getApplicationContext(),
                R.anim.animation, R.anim.animation2).toBundle();
        startActivity(intentActivity,animation);

      }
   });

    ll_logout.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {

        new UserSharedPrefrence(mContext).clearPrefrence();
        new BleSharedPrefrence(mContext).clearPrefrence();
        finish();
    }
   });

  }

 public void showAlertDialog(String Message) {
final Dialog dialog = new Dialog(mContext);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(
        new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setCancelable(false);
dialog.setContentView(R.layout.cart_dialog);

TextView txtdetail = (TextView) dialog.findViewById(R.id.txtdetail);
TextView txtno = (TextView) dialog.findViewById(R.id.txtno);

txtno.setVisibility(View.GONE);

TextView txtyes = (TextView) dialog.findViewById(R.id.txtyes);

txtyes.setText("Ok");

txtdetail.setText(Message);
txtyes.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        dialog.dismiss();
    }
});
dialog.show();
}

 @Override
 public void onBackPressed() {
 if(rightSlider.isDrawerOpen(GravityCompat.START)){
    rightSlider.closeDrawer(GravityCompat.START);
  }
   else{

 super.onBackPressed();

   }

 }

Have you implemented ActionBarDrawerToggle for NavDrawer? 您是否为NavDrawer实现了ActionBarDrawerToggle You can assign it to your NavDrawer and set it to syncState() 您可以将其分配给NavDrawer并将其设置为syncState()

mBaseDrawerLayout.setDrawerListener(mBaseDrawerToggle);
mBaseDrawerToggle.syncState();

Follow this up: Creating a Navigation Drawer And below code to close NavDrawer when going to another activity: 继续进行以下操作: 创建导航抽屉,然后执行下面的代码以在转到另一个活动时关闭NavDrawer:

mBaseDrawerLayout.closeDrawer(mBaseDrawerList);
mBaseDrawerToggle.syncState();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM