如何在旧API上使用Actionbar.setHideOnContentScrollEnabled

时间:2015-01-24 15:12:45

标签: android android-5.0-lollipop android-actionbar-compat

我使用了这个xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:nestedScrollingEnabled="true">
     ...
     ...

</ScrollView>

活动中:

ActionBar myActionBar;
myActionBar = getSupportActionBar();
myActionBar.setHideOnContentScrollEnabled(true);

它适用于android 5,我想在较旧的API上使用它,但nestedScrollingEnabled仅在API 21上受支持。 我确信这应该适用于较旧的API,因为大多数Google应用都使用此功能。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

nestedScrollingEnabled用于允许子视图在父级内滚动。

取决于您ScrollView中是否有更多滚动子项,因此需要nestedScrollingEnabled

如果您只有一个ScrollView,则隐藏ActionBar应该在滚动回调中收集的dy数量上完成。这基本上是setHideOnContentScrolled()的作用。您可以在Y轴上将Toolbar(如果使用工具栏作为操作栏)偏移/翻译一定量,或者只在ActionBar上调用.hide()。这适用于所有版本。

相关问题