我在活动上完成了手动导航抽屉,并完成了XML菜单,并添加了NavigationView.onnavigationItemSelectedListener作为接口,但是我的菜单项目仍然不可单击。这是下面的代码
package project.senior.health;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.view.GravityCompat;
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.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import com.backendless.Backendless;
import com.backendless.exceptions.BackendlessFault;
public class LoginSuccessActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener
{
private Button logoutButton;
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mToggle;
private Toolbar mToolbar;
public void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
setContentView( R.layout.login_success );
mDrawerLayout=(DrawerLayout) findViewById(R.id.drawerLayout);
mToggle= new ActionBarDrawerToggle(this,mDrawerLayout,R.string.open,R.string.close);
mDrawerLayout.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ImageButton simpleImageButton = (ImageButton)findViewById(R.id.imageButton2);
simpleImageButton.setImageResource(R.drawable.i4);
simpleImageButton.setBackgroundColor(Color.TRANSPARENT);
ImageButton simpleImageButton1 = (ImageButton)findViewById(R.id.imageButton3);
simpleImageButton1.setImageResource(R.drawable.i3);
simpleImageButton1.setBackgroundColor(Color.TRANSPARENT);
ImageButton simpleImageButton2 = (ImageButton)findViewById(R.id.imageButton4);
simpleImageButton2.setImageResource(R.drawable.i2);
simpleImageButton2.setBackgroundColor(Color.TRANSPARENT);
initUI();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (mToggle.onOptionsItemSelected(item))
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.Profile) {
// Handle the camera action
} else if (id == R.id.Nutrition) {
} else if (id == R.id.Workouts) {
startActivity(new Intent(LoginSuccessActivity.this, BuildTabbedAct.class));
} else if (id == R.id.Friends) {
} else if (id == R.id.Search) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawerLayout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
private void initUI()
{
// logoutButton = (Button) findViewById( R.id.logoutButton );
//
// logoutButton.setOnClickListener( new View.OnClickListener()
// {
// @Override
// public void onClick( View view )
// {
// onLogoutButtonClicked();
// }
// } );
}
private void onLogoutButtonClicked()
{
Backendless.UserService.logout( new DefaultCallback<Void>( this )
{
@Override
public void handleResponse( Void response )
{
super.handleResponse( response );
startActivity( new Intent( LoginSuccessActivity.this, LoginActivity.class ) );
finish();
}
@Override
public void handleFault( BackendlessFault fault )
{
if( fault.getCode().equals( "3023" ) ) // Unable to logout: not logged in (session expired, etc.)
handleResponse( null );
else
super.handleFault( fault );
}
} );
}
public void profile(View v){
startActivity(new Intent(LoginSuccessActivity.this, test.class));
}
public void nutrition(View v){
startActivity(new Intent(LoginSuccessActivity.this, test.class));
}
public void build(View v){
startActivity(new Intent(LoginSuccessActivity.this, BuildTabbedAct.class));
}
public void lose(View v){
startActivity(new Intent(LoginSuccessActivity.this, test.class));
}
}
我只测试1意图,该项目的ID是正确的,请有任何想法或技巧吗?感谢!
我看到您实现了navigationView.onnavigationEmselectectectectectener,但您不向活动注册侦听器(示例:navigationView.setNavigationNavigationItemSelectedListener(this))。请检查此!