2017-08-11 119 views

回答

1

在你MainActivity.java你應該有一個被覆蓋的功能,看起來像這樣:

@SuppressWarnings("StatementWithEmptyBody") 
@Override 
public boolean onNavigationItemSelected(MenuItem item) { 
    // Handle navigation view item clicks here. 
    int id = item.getItemId(); 

    if (id == R.id.option1) { 

    } else if (id == R.id.option2) { 

    } else if (id == R.id.option3) { 

    } else if (id == R.id.option4) { 

    } 

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    drawer.closeDrawer(GravityCompat.START); 
    return true; 
} 

,如果你想,當你點擊選項1按鈕,那麼你應該添加一個意圖爲要活動啓動另一個活動打開option1'if'括號:

Intent loginintent = new Intent(this, activity_youractivity.class); 
startActivity(loginintent); 

這裏的activity_youractivity是你想繼續學習的java文件的名稱。
Ex-Home.class(Home是活動的java文件名,.class用於調用該活動的類,該固定類可用)
您也可以在menu.xml中更改ID,並且必須在此函數中重複該更改。
希望這會有所幫助。

+0

感謝兄弟,我做到了 – Mike