1

我在我的應用程序中實現導航抽屜,在大多數情況下它似乎是工作確定。Home鍵從抽屜圖標切換到了上旋轉按鈕 - 只有當NAV打開抽屜

我home鍵設置爲導航抽屜圖標(漢堡),這仍然存在跨正常輪換。如圖1(人像)和圖像2(旋轉後的風景)所示。 Image 1

Image 2

但是如果我打開抽屜資產淨值,再旋轉屏幕,然後關閉導航抽屜,主頁按鈕變爲了按鈕,可以在圖像中可以看出3. Image 3

我試圖改變周圍的東西,所以它不斷保持漢堡包圖標,但有沒有運氣。

我的代碼爲MainActivity低於。

public class MainActivity extends AppCompatActivity { 
private String[] mNavigationDrawerItemTitles; 
private DrawerLayout mDrawerLayout; 
private ListView mDrawerList; 
Toolbar toolbar; 
private String mDrawerTitle; 
private String mTitle; 
ActionBarDrawerToggle mDrawerToggle; 
private static int sNavPosition = 0; 
private static final String NAV_POSITION_KEY = "navKey"; 
private static final String TAG = MainActivity.class.getSimpleName(); 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    mDrawerTitle = getTitle().toString(); 
    mTitle = getTitle().toString(); 
    mNavigationDrawerItemTitles = getResources().getStringArray(R.array.drawer_fragment_items); 
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 
    mDrawerList = (ListView) findViewById(R.id.left_drawer); 
    setUpToolbar(); 
    NavDrawerItem[] navDrawerItems = new NavDrawerItem[4]; 

    navDrawerItems[0] = new NavDrawerItem(getString(R.string.nav_home)); 
    navDrawerItems[1] = new NavDrawerItem(getString(R.string.nav_aims)); 
    navDrawerItems[2] = new NavDrawerItem(getString(R.string.nav_arttrail)); 
    navDrawerItems[3] = new NavDrawerItem(getString(R.string.nav_submission)); 

    DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.drawer_list_item,navDrawerItems); 
    View header = getLayoutInflater().inflate(R.layout.drawer_header,null); 
    mDrawerList.addHeaderView(header); 
    mDrawerList.setAdapter(adapter); 
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); 
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 
    mDrawerLayout.addDrawerListener(mDrawerToggle); 
    setUpDrawerToggle(); 
    if (savedInstanceState != null && savedInstanceState.containsKey(NAV_POSITION_KEY)){ 
     sNavPosition = savedInstanceState.getInt(NAV_POSITION_KEY); 
    } 
    new DrawerItemClickListener().selectItem(sNavPosition); 
} 

private void setUpDrawerToggle(){ 
    mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout,toolbar,R.string.app_name,R.string.app_name); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    mDrawerToggle.setDrawerIndicatorEnabled(true); 
    mDrawerToggle.syncState(); 
} 



@Override 
protected void onPostCreate(@Nullable Bundle savedInstanceState) { 
    super.onPostCreate(savedInstanceState); 
    mDrawerToggle.syncState(); 
} 

private void setUpToolbar(){ 
    toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 

} 



@Override 
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { 
    super.onSaveInstanceState(outState, outPersistentState); 
    outState.putInt(NAV_POSITION_KEY,sNavPosition); 
} 

}

我已經排除不必要的代碼就點擊聽衆進行導航。

任何幫助或建議將不勝感激。謝謝。

回答

2

嘗試從烏爾
setUpDrawerToggle();方法

Edit: setDisplayHomeAsUpEnabled(false) hides the default back button 
+0

不幸的是沒有工作拆卸getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mDrawerToggle.setDrawerIndicatorEnabled(true);,感謝您的幫助反正。歡迎提出建議 – AF1001

+0

getSupportActionBar()。setDisplayHomeAsUpEnabled(false);用於隱藏默認後退按鈕。 –

+0

我決定在onDrawerClose事件中設置DisplayHomeAsUpEnabled(false),它現在正在工作。謝謝。 – AF1001