Last active
August 29, 2015 14:24
-
-
Save dmitriy-chernysh/ab058dd60c4448c34215 to your computer and use it in GitHub Desktop.
Android AppBar with CoordinatorLayout (hide AppBar when scrolling up)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
compile fileTree(include: ['*.jar'], dir: 'libs') | |
compile 'com.android.support:appcompat-v7:22.2.0' | |
compile 'com.android.support:design:22.2.0' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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