在没有导航抽屉的Android ActionBar上模拟导航抽屉图标

时间:2014-06-26 06:40:49

标签: android navigation-drawer

我在Android项目中使用了SlidingLayer库,我想模拟主页按钮,就好像我使用了导航抽屉一样。我正在使用Action Bar,我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

Find this blog post 它看起来与您的问题类似

public void updateNavigationDrawerIcon(Drawable drawable) { Method setHomeAsUpIndicator; try { setHomeAsUpIndicator = ActionBar.class.getDeclaredMethod("setHomeAsUpIndicator", Drawable.class); setHomeAsUpIndicator.invoke(getActionBar(), drawable); } catch (NoSuchMethodException e) { Log.e("CHECK", "No Such Method"); View home = findViewById(android.R.id.home); ViewGroup parent = (ViewGroup) home.getParent(); int childCount = parent.getChildCount(); if (childCount == 2) { final View first = parent.getChildAt(0); final View second = parent.getChildAt(1); final View up = first.getId() == android.R.id.home ? second : first; ((ImageView) up).setImageDrawable(drawable); } } catch (Exception e) { e.printStackTrace(); } }

一切顺利