【问题标题】:Android Action Bar Custom View Navigation Indicator hiddenAndroid Action Bar 自定义视图导航指示器隐藏
【发布时间】:2013-10-07 20:47:53
【问题描述】:

我正在向操作栏添加自定义视图,但是当我这样做时,导航指示器图标不显示。当我不显示自定义视图时,指示器会显示并且工作正常。

getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setBackgroundDrawable(getResources().getDrawable(navConf.getBackgroundDraw()));

    if (0 != navConf.getActionBarCustomView()){
        getActionBar().setCustomView(navConf.getActionBarCustomView());
        getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM
                | ActionBar.DISPLAY_SHOW_HOME);
    }

    try{
        mDrawerToggle = new ActionBarDrawerToggle(
                this,
                mDrawerLayout,
                navConf.getDrawerIcon(),
                navConf.getDrawerOpenDesc(),
                navConf.getDrawerCloseDesc()
                ) {
            public void onDrawerClosed(View view) {
                getActionBar().setTitle(mTitle);
                ActivityCompat.invalidateOptionsMenu(AbstractNavDrawerActivity.this);
            }

            public void onDrawerOpened(View drawerView) {
                getActionBar().setTitle(mDrawerTitle);
                ActivityCompat.invalidateOptionsMenu(AbstractNavDrawerActivity.this);
            }
        };
    }
    catch (Exception ex){
        Log.e("ActionBarDrawerToggle: ", ex.toString());
    }

    mDrawerLayout.setDrawerListener(mDrawerToggle);

【问题讨论】:

    标签: android android-actionbar navigation-drawer custom-view


    【解决方案1】:
        getActionBar().setDisplayShowCustomEnabled(true);
        getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        getActionBar().setIcon(R.mipmap.icon_menu);
        getActionBar().setCustomView(getLayoutInflater().inflate(R.layout.actionbar_main, null),
                new ActionBar.LayoutParams(
                        ActionBar.LayoutParams.WRAP_CONTENT,
                        ActionBar.LayoutParams.MATCH_PARENT,
                        Gravity.CENTER
                )
        );
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                R.mipmap.icon_menu, //nav menu toggle icon
                0, // nav drawer open - description for accessibility
                0 // nav drawer close - description for accessibility
        ) {
            public void onDrawerClosed(View view) {
                getActionBar().setTitle(mTitle);
                // calling onPrepareOptionsMenu() to show action bar icons
                invalidateOptionsMenu();
            }
    
            public void onDrawerOpened(View drawerView) {
                getActionBar().setTitle(mDrawerTitle);
                // calling onPrepareOptionsMenu() to hide action bar icons
                invalidateOptionsMenu();
            }
        };
    

    【讨论】:

    • 也许你想为这个解决方案写一些额外的话?
    【解决方案2】:

    将此标志添加为 ActionBar 显示选项:

    ActionBar.DISPLAY_HOME_AS_UP
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多