我在Android项目中使用了SlidingLayer库,我想模拟主页按钮,就好像我使用了导航抽屉一样。我正在使用Action Bar,我怎么能这样做?
答案 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();
}
}
一切顺利