1
我在我的oncreate函數中使用此代碼通過按應用程序圖標打開導航抽屜。Android - 構造函數ActionBarDrawerToggle未定義
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
(DrawerLayout) findViewById(R.id.left_drawer), /* DrawerLayout object */
getResources().getDrawable(R.drawable.ic_drawer), /* nav drawer icon to replace 'Up' caret */
getString(R.string.drawer_open), /* "open drawer" description */
getString(R.string.drawer_close) /* "close drawer" description */
) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
getActionBar().setTitle(R.string.title_activity_add);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(R.string.drawer_title);
}
};
現在它說: 「構造ActionBarDrawerToggle(AddActivity,DrawerLayout,繪製對象,字符串,字符串)是不確定的」。我已經導入了android.support.v4.app.ActionBarDrawerToggle。問題在哪裏?
謝謝。我改變了構造函數和參數,現在它說「ActionBarToggle不能解析爲類型」。我試圖導入android.support.v4.app.ActionBarToggle,但它沒有幫助。 – user2971688
@ user2971688:對不起,該類是「ActionBarDrawerToggle」,而不是「ActionBarToggle」。我已經解決了我的答案。我只是想讓你改變構造函數調用的最後三個參數。 – CommonsWare
謝謝,它現在似乎工作。我可以問你另一個簡單的問題:我想在用戶啓動應用程序時總是打開抽屜式導航器。我如何使用openDrawer()函數?我的導航抽屜的ID是left_drawer。 – user2971688