2016-12-28 58 views
1

我正在制作和发布一个包含android web视图的web应用程序。在增强我的应用程序时,我试图在用户滚动web视图时执行该操作,操作栏消失。我用一些库编写了一些代码,可以检测用户的滚动动作,并使其工作。 但是,它不工作顺利。我找到了答案,我找不到..我捕获了它的工作原理,并与默认浏览器进行比较。 [YouTube链接:https://youtu.be/rtgB0FSP8ek](android)Hidng actionbar/toolbar是否顺利?

我做了什么,

 // When scrolling 
     public void onUpOrCancelMotionEvent(ScrollState scrollState) { 
      if (scrollState == ScrollState.UP) { 
       if(actionbar.isShowing()) actionbar.hide(); 
      } else if (scrollState == ScrollState.DOWN) { 
       if(!actionbar.isShowing())actionbar.show(); 
      } 
     } 

,并在我的活动主题,我加了这个,

<item name="windowActionBarOverlay">true</item> 

,并在我的Web页面的版面

<LinearLayout 
     android:animateLayoutChanges="true" 
     android:fitsSystemWindows="true" 
     ..... 

新年快乐!

+1

查看CollapseToolbarLayout。这是你的救星。 –

+0

@SergeyShustikov谢谢你的评论先生!你的意思是如果我改变我的根布局,那可以解决?其实,我不知道关于CollapseToolBarLayout。 – SeetFack

+0

@Sergey是对的... CollapsingToolbarLayout是你的答案...教程很容易在谷歌搜索 – BiGGZ

回答

0

ActionBar显示/隐藏,没有任何动画,因此您应该将动画添加到工具栏以实现平滑的显示/隐藏转换。

void hideActionBar(){ 
    ActionBar ab = getSupportActionBar(); 
    if (ab != null && ab.isShowing()) { 
     if(toolbar != null) { 
      toolbar.animate().translationY(-212).alpha(0).setDuration(600L) 
        .setListener(new Animator.AnimatorListener() { 
         @Override 
         public void onAnimationStart(Animator animation) { 

         } 

         @Override 
         public void onAnimationEnd(Animator animation) { 
          ab.hide(); 
         } 

         @Override 
         public void onAnimationCancel(Animator animation) { 

         } 

         @Override 
         public void onAnimationRepeat(Animator animation) { 

         } 
        }).start(); 
     } else { 
      ab.hide(); 
     } 
    } 
} 

void showActionBar(){ 
    ActionBar ab = getSupportActionBar(); 
    if (ab != null && !ab.isShowing()) { 
     ab.show(); 
     if(toolbar != null) { 
      toolbar.animate().translationY(0).alpha(1).setDuration(600L).start(); 
     } 
    } 
}