2015-06-09 2 views
1

style.xmlнавигации значок ящик не отображается с помощью AppCompat v7

<style name="AppBaseTheme" parent="Theme.AppCompat.Light"> 
     <item name="android:homeAsUpIndicator">@drawable/ic_back</item> 
     <item name="homeAsUpIndicator">@drawable/ic_back</item> 
    </style> 

MainActivity.java

ActionBar actionBar = getSupportActionBar(); 

actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP); 
     actionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent))); 
     View actionBarView = inflator.inflate(R.layout.custom_title, null); 

actionBar.setCustomView(actionBarView); 


     mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, 
       R.drawable.ic_action_nav_menu, //nav menu toggle icon 
       R.string.app_name, // nav drawer open - description for accessibility 
       R.string.app_name // nav drawer close - description for accessibility 
     ) { 
      public void onDrawerClosed(View view) { 
       tvTitle.setText(mTitle); 
       //getActionBar().setTitle(mTitle); 
       // calling onPrepareOptionsMenu() to show action bar icons 
       invalidateOptionsMenu(); 
      } 

      public void onDrawerOpened(View drawerView) { 
       tvTitle.setText(mDrawerTitle); 
       //getActionBar().setTitle(mDrawerTitle); 
       // calling onPrepareOptionsMenu() to hide action bar icons 
       invalidateOptionsMenu(); 
      } 
     }; 

enter image description here

вы можете увидеть в изображении выше, где в черном круге я хочу покажите изображение с тремя линиями, а не на обратном символе.

ответ

2

Использование android.support.v7 вместо android.support.v4 следующим образом:

import android.support.v7.app.ActionBarDrawerToggle; 

И изменить mDrawerToggle следующим:

mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, 
      R.string.app_name, // nav drawer open - description for accessibility 
      R.string.app_name // nav drawer close - description for accessibility 
    )... 

Добавить следующие коды:

actionBar.setDisplayHomeAsUpEnabled(true); 
actionBar.setHomeButtonEnabled(true); 

// Defer code dependent on restoration of previous instance state. 
mDrawerLayout.post(new Runnable() { 
    @Override 
    public void run() { 
     mDrawerToggle.syncState(); 
    } 
}); 
0

сменить пакет импорт android.support.v4.app.ActionBarDrawerToggle; до import android.support.v7.app.ActionBarDrawerToggle;

mDrawerToggle = new ActionBarDrawerToggle (это, mDrawerLayout, R.string.app_name, R.string.app_); mDrawerlayout is объект DrawerLayout

Смежные вопросы