基本上,如果这还不够清楚,here就是我想要实现的目标.我不想使用this library (MaterialMenu),我想使用官方的AppCompat lib来扩展可能.
由于this solution,我实现了这个效果,但是当更换片段时,我无法弄清楚如何将ActionbarDrawerToggle作为后退按钮.
所以我的问题是:如果后箭头图标仍然是ActionbarDrawerToggleonce,Fragement已被替换?在这种情况下,我如何覆盖它,以便它像onBackpressed(),而不是打开抽屉?我已经尝试了这个,但它不起作用:
@OverrIDe public boolean onoptionsItemSelected(MenuItem item) { switch (item.getItemID()) { case androID.R.ID.home: getActivity().onBackpressed(); return true; } return false; }
提前致谢.
解决方法 如果你手动打开它,我认为在抽屉里面跟踪更清洁.这就是我最终做的事情:public class ManualActionbarDrawerToggle extends ActionbarDrawerToggle { private static final float MENU_position = 0f; private static final float ARROW_position = 1.0f; private final int animationLength; private final DrawerLayout drawerLayout; private final Activity activity; private State currentState; private enum State { UP_ARROW,MENU } public ManualActionbarDrawerToggle(Activity activity,DrawerLayout drawerLayout,int openDrawerContentDescriptionResource,int closeDrawerContentDescriptionResource) { super(activity,drawerLayout,openDrawerContentDescriptionResource,closeDrawerContentDescriptionResource); animationLength = activity.getResources().getInteger(androID.R.integer.config_shortAnimTime); this.drawerLayout = drawerLayout; this.activity = activity; currentState = State.MENU; } public voID animatetoBackArrow() { ValueAnimator anim = ValueAnimator.offloat(MENU_position,ARROW_position); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @OverrIDe public voID onAnimationUpdate(ValueAnimator valueAnimator) { float slIDeOffset = (float) valueAnimator.getAnimatedValue(); onDrawerSlIDe(drawerLayout,slIDeOffset); } }); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(animationLength); anim.start(); currentState = State.UP_ARROW; } public voID animatetoMenu() { ValueAnimator anim = ValueAnimator.offloat(ARROW_position,MENU_position); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @OverrIDe public voID onAnimationUpdate(ValueAnimator valueAnimator) { float slIDeOffset = (float) valueAnimator.getAnimatedValue(); onDrawerSlIDe(drawerLayout,slIDeOffset); } }); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(animationLength); anim.start(); currentState = State.MENU; } @OverrIDe public boolean onoptionsItemSelected(MenuItem item) { switch (item.getItemID()) { case (androID.R.ID.home): if (currentState == State.UP_ARROW) { activity.onBackpressed(); return true; } } return super.onoptionsItemSelected(item); }}总结
以上是内存溢出为你收集整理的Android 5.0 – 以编程方式将AppCompat v7 21主页图标从汉堡动画设置为后退箭头全部内容,希望文章能够帮你解决Android 5.0 – 以编程方式将AppCompat v7 21主页图标从汉堡动画设置为后退箭头所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)