簡體   English   中英

Android ActionBar自定義視圖和NavigationDrawer

[英]Android ActionBar custom view and NavigationDrawer

我的項目主要活動遇到了一些問題。 我有一個帶有NavigationDrawer的SherlockFragmentActivity和一個帶有自定義視圖的ActionBar上的SearchView。 問題是,當我在SearchView上鍵入查詢時,我可以進行搜索並且一切正常,但是當我關閉SearchView時,ActionBar自定義視圖和NavigationDrawer切換開關從ActionBar中消失了。

這是圖形問題 在此處輸入圖片說明

這是我的NavigationDrawer

private void initialiseDrawer(){
    this.drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
    this.drawerList = (ListView)findViewById(R.id.navigation_drawer);
    this.drawerAdapter = new NavigationDrawerAdapter(MainActivity.this);
    this.drawerList.setAdapter(drawerAdapter);
    this.drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            handleDrawerSelectedPosition(position);
        }
    });

    //getSupportActionBar().setHomeButtonEnabled(true);
    this.drawerToggle = new ActionBarDrawerToggle(this, this.drawerLayout, R.drawable.drawer,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close){
        public void onDrawerOpened(View view){
            super.onDrawerOpened(view);
            hideMenu();
        }

        public void onDrawerClosed(View view){
            super.onDrawerClosed(view);
            showMenu();
        }
    };

    this.drawerLayout.setDrawerListener(drawerToggle);
    this.drawerToggle.syncState();
}

這就是我設置ActionBar的方式

private void showCustomActionBarView(){
    getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayUseLogoEnabled(false);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setCustomView(R.layout.action_bar_layout);
}

拆下SearchView后,如何顯示我的自定義View和DrawerToggle?

好吧,我在這里找到了自己的答案,我使用的是SherlockActionBar和支持庫4.0,我剛剛刪除了sherlock庫,並將支持庫升級到v7.21.03,實現了工具欄,所有問題都解決了,希望對我以外的人有所幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM