我使用自定义导航图标,因此我需要drawerToggle.setDrawerIndicatorEnabled(false);
。但现在,单击我的自定义图标时,我的Navdrawer无法打开。
任何想法如何实现这一目标?我还需要ActionBarDrawerToggle吗?
public void setUpActionBar() {
actionBar = (Toolbar) findViewById(R.id.custom_screen_toolbar);
setSupportActionBar(actionBar);
actionBar.setBackgroundResource(R.drawable.divider_action_bar);
actionBar.setNavigationIcon(R.drawable.action_bar_menu);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
drawerLayout, /* DrawerLayout object */
actionBar, /* custom action bar */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, 0);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
drawerLayout.setDrawerListener(drawerToggle);
drawerToggle.setDrawerIndicatorEnabled(false);
drawerToggle.syncState();
}
我也尝试使用drawerToggle.setHomeAsUpIndicator(R.drawable.icon);
,这样我就可以在不使用操作栏中的setNavigationIcon
的情况下更改te图标,但它不会更改图标。
答案 0 :(得分:1)
如果您拨打from django.db import models
from datetime import datetime
from django.contrib import admin
class Category(models.Model):
category_name = models.CharField(max_length=200)
category_id = models.CharField(max_length=200)
class Meta:
app_label = 'ebay'
def __unicode__(self):
return u'%s' % (self.category_id)
class MyCategory(Category):
@staticmethod
def autocomplete_search_fields():
return ("category_name__icontains", "category_id__icontains")
class Meta:
proxy = True
class Listing(models.Model):
ebay_id = models.CharField(max_length=200,null=True)
amazon_id = models.CharField(max_length=200)
category = models.ForeignKey(MyCategory)
class Meta:
app_label = 'ebay'
def __unicode__(self):
return u'%s' % (self.ebay_id)
class ListingOptions(admin.ModelAdmin):
# define the raw_id_fields
raw_id_fields = ('category',)
# define the autocomplete_lookup_fields
autocomplete_lookup_fields = {
'fk': ['category'],
}
和drawerToggle.setHomeAsUpIndicator(R.drawable.icon);
,则会启动
drawerToggle.setDrawerIndicatorEnabled(false);
和
public void setHomeAsUpIndicator(Drawable indicator) {
if(indicator == null) {
this.mHomeAsUpIndicator = this.getThemeUpIndicator();
this.mHasCustomUpIndicator = false;
} else {
this.mHomeAsUpIndicator = indicator;
this.mHasCustomUpIndicator = true;
}
if(!this.mDrawerIndicatorEnabled) {
this.setActionBarUpIndicator(this.mHomeAsUpIndicator, 0);
}
虽然您调用了setHomeAsUpIndicator(Drawable指示符),因为mDrawerIndicatorEnabled为false,因此它不会更改图标。(但如果您先调用public void setDrawerIndicatorEnabled(boolean enable) {
if(enable != this.mDrawerIndicatorEnabled) {//if you set enable be "false", below sentences do not run, because the default value of mDrawerIndicatorEnabled is false
if(enable) {
this.setActionBarUpIndicator((Drawable)this.mSlider, this.mDrawerLayout.isDrawerOpen(8388611)?this.mCloseDrawerContentDescRes:this.mOpenDrawerContentDescRes);
} else {
this.setActionBarUpIndicator(this.mHomeAsUpIndicator, 0);
}
this.mDrawerIndicatorEnabled = enable;
}
}
然后调用setDrawerIndicatorEnabled
,则可以也改变图标。)
如果您致电setHomeAsUpIndicator
,图标会发生变化,因为它会调用toolbar.setNavigationIcon(R.mipmap.ic_launcher);
中的setActionBarUpIndicator
。您将看到工具栏将为其导航图标设置此drawable。
ActionBarDrawerToggle.java
如果你想通过点击打开抽屉菜单,你应该为这个' navigationIcon'设置一个点击监听器,因为在你调用它之后,系统将无法为你提供帮助。
答案 1 :(得分:0)
setDrawerIndicatorEnabled(false);
将禁用抽屉指示器,因此我的猜测是它需要设置为true。此外,如果您需要抽屉的自定义图标,您可以将其设置为,
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.earth, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
)
drawable参数应该替换up caret。
有用的link下载示例。