From 2ea6b5d0606955b7dae8a052bc80a6825f852981 Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Fri, 20 Feb 2015 18:45:42 +0000 Subject: [PATCH] Add hide on scroll demo Change-Id: I1c76ad7c5f2c37a4cdfde4e73b9579ec3a633fcb --- samples/Support7Demos/AndroidManifest.xml | 9 ++++ .../Support7Demos/res/drawable/gradient.xml | 20 +++++++++ .../res/layout/action_bar_hide_scroll.xml | 33 +++++++++++++++ samples/Support7Demos/res/values/strings.xml | 1 + .../supportv7/app/ActionBarHideOnScroll.java | 42 +++++++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 samples/Support7Demos/res/drawable/gradient.xml create mode 100644 samples/Support7Demos/res/layout/action_bar_hide_scroll.xml create mode 100644 samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarHideOnScroll.java diff --git a/samples/Support7Demos/AndroidManifest.xml b/samples/Support7Demos/AndroidManifest.xml index a84dc225f..26f2a5778 100644 --- a/samples/Support7Demos/AndroidManifest.xml +++ b/samples/Support7Demos/AndroidManifest.xml @@ -222,6 +222,15 @@ + + + + + + + diff --git a/samples/Support7Demos/res/drawable/gradient.xml b/samples/Support7Demos/res/drawable/gradient.xml new file mode 100644 index 000000000..1b654a0ed --- /dev/null +++ b/samples/Support7Demos/res/drawable/gradient.xml @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file diff --git a/samples/Support7Demos/res/layout/action_bar_hide_scroll.xml b/samples/Support7Demos/res/layout/action_bar_hide_scroll.xml new file mode 100644 index 000000000..a80140f92 --- /dev/null +++ b/samples/Support7Demos/res/layout/action_bar_hide_scroll.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/samples/Support7Demos/res/values/strings.xml b/samples/Support7Demos/res/values/strings.xml index 348014295..6e2c2f756 100644 --- a/samples/Support7Demos/res/values/strings.xml +++ b/samples/Support7Demos/res/values/strings.xml @@ -58,6 +58,7 @@ AppCompat/Action Bar/Navigation Drawer Toggle AppCompat/Action Bar/Preferences AppCompat/Action Bar/Action Mode + AppCompat/Action Bar/Hide on Scroll AppCompat/Widgets/Buttons AppCompat/Widgets/Spinners AppCompat/Widgets/Text Input diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarHideOnScroll.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarHideOnScroll.java new file mode 100644 index 000000000..61bd90bd1 --- /dev/null +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarHideOnScroll.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.android.supportv7.app; + +import com.example.android.supportv7.R; + +import android.os.Bundle; +import android.support.v4.view.WindowCompat; +import android.support.v7.app.AppCompatActivity; + +/** + * This demonstrates usage of the Action Bar's hide on content scroll + */ +public class ActionBarHideOnScroll extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Hide on content scroll requires an overlay action bar, so request one + supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY); + + setContentView(R.layout.action_bar_hide_scroll); + + // Enable hide on scroll + getSupportActionBar().setHideOnContentScrollEnabled(true); + } + +}