无法解析方法'addDrawerListener(android.support.v7.app.ActionBarDrawerToggle)'

时间:2016-05-28 12:21:33

标签: android

package com.shafi.shafqat.listview;

import android.support.design.widget.NavigationView; import
android.support.v4.widget.DrawerLayout; import
android.support.v7.app.ActionBarDrawerToggle; import
android.support.v7.app.AppCompatActivity; import
android.support.v7.widget.Toolbar; import android.view.MenuItem;
import android.view.View; import android.widget.TextView; import
android.widget.Toast;

 public class rawerActivity extends AppCompatActivity{

     DrawerLayout drawer;
     NavigationView navView;
     Toolbar toolbar;
     public void initNavDrawer(){
         navView = (NavigationView) findViewById(R.id.navigation_view);
         navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
             @Override
             public boolean onNavigationItemSelected(MenuItem item) {

                 switch (item.getItemId()){
                     case R.id.bikes:
                         Toast.makeText(getApplicationContext(), "Bikes Selected", Toast.LENGTH_SHORT).show();
                         break;
                     case R.id.accessories:
                         Toast.makeText(getApplicationContext(), "Accessories Selected", Toast.LENGTH_SHORT).show();
                         break;
                     case R.id.contact:
                         Toast.makeText(getApplicationContext(), "Contact Us Selected", Toast.LENGTH_SHORT).show();
                         break;
                     case R.id.login:
                         Toast.makeText(getApplicationContext(), "Log In Selected", Toast.LENGTH_SHORT).show();
                         break;
                 }
                 return true;
             }
         });


         toolbar = (Toolbar) findViewById(R.id.toolbar);
         View header = navView.getHeaderView(0);
         TextView tv_email = (TextView)header.findViewById(R.id.user_name);
         tv_email.setText("skshafqat@gmail.com");
         drawer = (DrawerLayout)findViewById(R.id.drawer_layout);

         ActionBarDrawerToggle actionBarDrawerToggle =
                 new ActionBarDrawerToggle(this,drawer,toolbar,R.string.drawer_open,R.string.drawer_close){

                     @Override
                     public void onDrawerClosed(View v){
                         super.onDrawerClosed(v);
                     }

                     @Override
                     public void onDrawerOpened(View v) {
                         super.onDrawerOpened(v);
                     }

                 };
         drawer.addDrawerListener(actionBarDrawerToggle);
         actionBarDrawerToggle.syncState();
     }

 }

我昨天测试了相同的代码并且它有效。但现在,当我想将此代码与另一个模块组合时,它会突出显示以下drawer.addDrawerListener(actionBarDrawerToggle);行的红色。将鼠标悬停在其上时,显示错误无法解析方法addDrawerListener(android.support.v7.app.ActionBarDrawerToggle)

请帮忙......

0 个答案:

没有答案