Skip to content

Instantly share code, notes, and snippets.

@dmitriy-chernysh
Last active August 29, 2015 14:24
Show Gist options
  • Save dmitriy-chernysh/ab058dd60c4448c34215 to your computer and use it in GitHub Desktop.
Save dmitriy-chernysh/ab058dd60c4448c34215 to your computer and use it in GitHub Desktop.
Android AppBar with CoordinatorLayout (hide AppBar when scrolling up)
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlways" /> <!--use layout_scrollFlags for hide view-->
</android.support.design.widget.AppBarLayout>
<!-- here is scrollable View with app:layout_behavior="@string/appbar_scrolling_view_behavior"-->
</android.support.design.widget.CoordinatorLayout>
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.0'
}
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
}
.....................
....................
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment