在写这个线程之前,我尝试实现了我在stackoverflow中找到的不同解决方案,但没有任何工作正常。如何更改Android中的汉堡包图标(NavigationDrawer)
我正在开发一个使用自定义导航抽屉的Android应用程序,我必须更改操作栏的标准图标(现在是工具栏,对吧?)和设置图标。
这是我的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitleTextColor(Color.parseColor("#009754"));
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
而这正是我试图实现:
此解决方案不起作用:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitleTextColor(Color.parseColor("#009754"));
toolbar.setNavigationIcon(R.drawable.ic_draw);
setSupportActionBar(toolbar);
此解决方案不起作用:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(false);
toggle.setDrawerIndicatorEnabled(false);
toggle.setHomeAsUpIndicator(R.drawable.ic_custom_drawer_icon);
我不在乎t和为什么我不能更改图标,我不知道是什么问题...
为ActionBarDrawerToggle
然后通过调用'setNavigationOnClickListener(添加自定义的监听器)'上工具栏如[这里]所述(https://stackoverflow.com/a/32695966/876267)。 – Mehmed