diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fe6a0d4..6078fd8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,7 +6,7 @@ android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" - android:theme="@style/Theme.AppCompat.Light" > + android:theme="@style/AppTheme" > @@ -38,7 +38,8 @@ + android:label="@string/collapsing_toolbars" + android:theme="@style/NoActionBarTheme"> diff --git a/app/src/main/java/com/hisham/design/CollapsingToolbars.java b/app/src/main/java/com/hisham/design/CollapsingToolbars.java index 6c0d57d..7c74419 100644 --- a/app/src/main/java/com/hisham/design/CollapsingToolbars.java +++ b/app/src/main/java/com/hisham/design/CollapsingToolbars.java @@ -1,12 +1,55 @@ package com.hisham.design; import android.os.Bundle; +import android.support.design.widget.CollapsingToolbarLayout; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; +import android.widget.ImageView; /** * Created by faisal pc on 6/9/2015. + * + *
+ + +

Class Overview


+

CollapsingToolbarLayout is a wrapper for Toolbar which implements a collapsing app bar. + It is designed to be used as a direct child of a AppBarLayout. + CollapsingToolbarLayout contains the following features: + +

Collapsing title

+ A title which is larger when the layout is fully visible but collapses and becomes smaller as + the layout is scrolled off screen. You can set the title to display via + setTitle(CharSequence). The title appearance can be tweaked via the + collapsedTextAppearance and expandedTextAppearance attributes. + +

Content scrim

+ A full-bleed scrim which is show or hidden when the scroll position has hit a certain threshold. + You can change this via setContentScrim(Drawable). + +

Status bar scrim

+ A scrim which is show or hidden behind the status bar when the scroll position has hit a certain + threshold. You can change this via setStatusBarScrim(Drawable). This only works + on LOLLIPOP devices when we set to fit system windows. + +

Parallax scrolling children

+ Child views can opt to be scrolled within this layout in a parallax fashion. + See COLLAPSE_MODE_PARALLAX and + setParallaxMultiplier(float). + +

Pinned position children

+ Child views can opt to be pinned in space globally. This is useful when implementing a + collapsing as it allows the Toolbar to be fixed in place even though this layout is + moving. See COLLAPSE_MODE_PIN.

+ + + + + +
+ * */ public class CollapsingToolbars extends AppCompatActivity { @@ -14,6 +57,23 @@ public class CollapsingToolbars extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_collaping_toolbars_layout); + + final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + + CollapsingToolbarLayout collapsingToolbar = + (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); + collapsingToolbar.setTitle("Wow Koala"); + + loadBackdrop(); + } + + private void loadBackdrop() { + final ImageView imageView = (ImageView) findViewById(R.id.backdrop); +// Glide.with(this).load(Cheeses.getRandomCheeseDrawable()).centerCrop().into(imageView); + imageView.setImageResource(R.drawable.koala); } @Override @@ -30,6 +90,11 @@ public boolean onOptionsItemSelected(MenuItem item) { // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); + if(id == R.id.home){ + finish(); + return true; + } + //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; diff --git a/app/src/main/java/com/hisham/design/MyListActivity.java b/app/src/main/java/com/hisham/design/MyListActivity.java index e57f4e1..12de4c8 100644 --- a/app/src/main/java/com/hisham/design/MyListActivity.java +++ b/app/src/main/java/com/hisham/design/MyListActivity.java @@ -46,7 +46,7 @@ protected void onCreate(Bundle savedInstanceState) { myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - startActivity(new Intent(getApplicationContext(), classes[position])); + MyListActivity.this.startActivity(new Intent(getApplicationContext(), classes[position])); } }); diff --git a/app/src/main/res/drawable/ic_discuss.png b/app/src/main/res/drawable/ic_discuss.png new file mode 100644 index 0000000..dc9341c Binary files /dev/null and b/app/src/main/res/drawable/ic_discuss.png differ diff --git a/app/src/main/res/drawable/koala.jpg b/app/src/main/res/drawable/koala.jpg new file mode 100644 index 0000000..78704a0 Binary files /dev/null and b/app/src/main/res/drawable/koala.jpg differ diff --git a/app/src/main/res/drawable/tulips.jpg b/app/src/main/res/drawable/tulips.jpg new file mode 100644 index 0000000..54c51eb Binary files /dev/null and b/app/src/main/res/drawable/tulips.jpg differ diff --git a/app/src/main/res/layout/activity_collaping_toolbars_layout.xml b/app/src/main/res/layout/activity_collaping_toolbars_layout.xml index feec332..04db0e1 100644 --- a/app/src/main/res/layout/activity_collaping_toolbars_layout.xml +++ b/app/src/main/res/layout/activity_collaping_toolbars_layout.xml @@ -1,27 +1,166 @@ - + + + + android:fitsSystemWindows="true" + tools:context=".CollapsingToolbars"> + android:layout_height="256dp" + android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" + android:fitsSystemWindows="true"> - + android:layout_height="match_parent" + app:layout_scrollFlags="scroll|exitUntilCollapsed" + android:fitsSystemWindows="true" + app:contentScrim="?attr/colorPrimary" + app:expandedTitleMarginStart="48dp" + app:expandedTitleMarginEnd="64dp"> + + android:layout_height="?attr/actionBarSize" + app:popupTheme="@style/ThemeOverlay.AppCompat.Light" + app:layout_collapseMode="pin" /> + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_tab_layout.xml b/app/src/main/res/menu/menu_tab_layout.xml index 7016410..19b3da0 100644 --- a/app/src/main/res/menu/menu_tab_layout.xml +++ b/app/src/main/res/menu/menu_tab_layout.xml @@ -2,6 +2,9 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context="com.hisham.design.TabLayoutActivity"> - + diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml index dba3c41..0f5308f 100644 --- a/app/src/main/res/values-v21/styles.xml +++ b/app/src/main/res/values-v21/styles.xml @@ -1,5 +1,13 @@ - + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..f1ad357 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,4 @@ + + + #FFF5F5F5 + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 47c8224..010887d 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -2,4 +2,9 @@ 16dp 16dp + + 256dp + 16dp + 16dp + 40dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 98124be..cadcebc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,5 +17,12 @@ TabLayoutActivity CoordinatorLayoutActivity Collapsing Toolbars + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Consequens enim est et post oritur, ut dixi. Illa tamen simplicia, vestra versuta. Sic vester sapiens magno aliquo emolumento commotus cicuta, si opus erit, dimicabit. Teneo, inquit, finem illi videri nihil dolere. Hoc loco tenere se Triarius non potuit. Ubi ut eam caperet aut quando? Quod cum dixissent, ille contra. Non dolere, inquam, istud quam vim habeat postea videro; Si longus, levis dictata sunt. Non enim quaero quid verum, sed quid cuique dicendum sit. Multoque hoc melius nos veriusque quam Stoici. Facile est hoc cernere in primis puerorum aetatulis. Hoc Hieronymus summum bonum esse dixit. Quo invento omnis ab eo quasi capite de summo bono et malo disputatio ducitur. Oratio me istius philosophi non offendit; Ita fit cum gravior, tum etiam splendidior oratio. De illis, cum volemus. Gerendus est mos, modo recte sentiat. Tum Piso: Quoniam igitur aliquid omnes, quid Lucius noster? Sed tamen intellego quid velit. Quis non odit sordidos, vanos, leves, futtiles? Te ipsum, dignissimum maioribus tuis, voluptasne induxit, ut adolescentulus eriperes P. Traditur, inquit, ab Epicuro ratio neglegendi doloris. Solum praeterea formosum, solum liberum, solum civem, stultost; Nunc haec primum fortasse audientis servire debemus. Qui-vere falsone, quaerere mittimus-dicitur oculis se privasse; Deprehensus omnem poenam contemnet. Hoc Hieronymus summum bonum esse dixit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Consequens enim est et post oritur, ut dixi. Illa tamen simplicia, vestra versuta. Sic vester sapiens magno aliquo emolumento commotus cicuta, si opus erit, dimicabit. Teneo, inquit, finem illi videri nihil dolere. Hoc loco tenere se Triarius non potuit. Ubi ut eam caperet aut quando? Quod cum dixissent, ille contra. Non dolere, inquam, istud quam vim habeat postea videro; Si longus, levis dictata sunt. Non enim quaero quid verum, sed quid cuique dicendum sit. Multoque hoc melius nos veriusque quam Stoici. Facile est hoc cernere in primis puerorum aetatulis. Hoc Hieronymus summum bonum esse dixit. Quo invento omnis ab eo quasi capite de summo bono et malo disputatio ducitur. Oratio me istius philosophi non offendit; Ita fit cum gravior, tum etiam splendidior oratio. De illis, cum volemus. Gerendus est mos, modo recte sentiat. Tum Piso: Quoniam igitur aliquid omnes, quid Lucius noster? Sed tamen intellego quid velit. Quis non odit sordidos, vanos, leves, futtiles? Te ipsum, dignissimum maioribus tuis, voluptasne induxit, ut adolescentulus eriperes P. Traditur, inquit, ab Epicuro ratio neglegendi doloris. Solum praeterea formosum, solum liberum, solum civem, stultost; Nunc haec primum fortasse audientis servire debemus. Qui-vere falsone, quaerere mittimus-dicitur oculis se privasse; Deprehensus omnem poenam contemnet. Hoc Hieronymus summum bonum esse dixit. + + Jarlsberg lancashire edam. Dolcelatte hard cheese brie st. agur blue + cheese caerphilly bavarian bergkase cheese and biscuits mascarpone. Cheeseburger swiss bavarian + bergkase cream cheese fromage frais cheesy feet port-salut airedale. St. agur blue cheese rubber + cheese caerphilly cheddar cheesecake cream cheese manchego lancashire. Roquefort squirty cheese + the big cheese. diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index ff6c9d2..c69964f 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,8 +1,23 @@ - + + + +