0
我開始一個新項目,只需從舊項目中複製/粘貼代碼,其中一切正常。在這一個切換按鈕不會改變狀態(這是唯一的箭頭,當我按下它不工作),如:導航抽屜切換不會改變狀態
到
打開/關閉抽屜工作正常使用刷卡觸摸
必須注意,我只使用一個具有佈局的活動:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/base_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:id="@+id/base_container_for_fragments"
android:layout_width="match_parent"
android:layout_height="match_parent">
//elements for screen
</RelativeLayout>
<!--that is just for drawer-->
<ListView
android:id="@+id/navigationDrawerList"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="@color/color_red_style" />
在我的活動:
//聲明瓦爾:
private ListView mDrawerList;
protected DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
CustomDrawerAdapter adapter;
List<DrawerItem> dataList;
在onCreate()
:
dataList = new ArrayList<DrawerItem>();
mDrawerLayout = (DrawerLayout) findViewById(R.id.base_layout);
mDrawerList = (ListView) findViewById(R.id.navigationDrawerList);
addDrawerItems();
setupDrawer();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
addDrawerItems()
好的工作
protected void setupDrawer() {
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open_drawer, R.string.close_drawer) {
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getSupportActionBar().setTitle(getResources().getString(R.string.bar_menu));
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getSupportActionBar().setTitle("produse");
// creates call to onPrepareOptionsMenu()
invalidateOptionsMenu();
}
};
mDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
,當然我把撥動手柄在onOptionsItemSelected(MenuItem item)
// Activate the navigation drawer toggle
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
那麼,有什麼問題,我只是無法實現...任何想法將不勝感激。
看看這個:https://developer.android.com/intl /zh-tw/training/implementing-navigation/nav-drawer.html#ActionBarIcon –
我意識到我的[故障](http://stackoverflow.com/a/32269830/3595288) – Choletski