![](images/gdg-hamburg-android/GDG_Android Hamburg_800.png)
<style name="AppTheme" parent="Theme.AppCompat.Light"> <item name="colorPrimary">#424242</item> <item name="colorAccent">#32a5ff</item> ...
<View android:background="?colorPrimary" ...
public static int getThemeColor(Context context, int attributeId) { TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(attributeId, tv, true); return tv.data; } int primaryColor = getThemeColor(this, R.attr.colorPrimary);
// SDK 21+ only <ImageView android:tint="?colorAccent" ...
// SDK 21+ Drawable drawable = context.getResources.getDrawable( R.drawable.background, context.getTheme()); drawable.setTint(primaryColor);
// below SDK 21 Drawable drawable = ContextCompat.getDrawable(context, R.drawable.background); DrawableCompat.wrap(drawable).setTint(primaryColor); // or Drawable drawable = ContextCompat.getDrawable(context, R.drawable.background); drawable.setColorFilter(primaryColor, PorterDuff.Mode.MERGE);
<View android:elevation="8dp" android:outlineProvider="bounds" ...
view.setElevation(8); view.setOutlineProvider(ViewOutlineProvider.BOUNDS);
dependencies { compile 'com.android.support:design:23.0.0' ...
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout); tabLayout.setupWithViewPager(viewPager);
<android.support.design.widget.TabLayout xmlns:app="http://schemas.android.com/apk/res-auto" app:tabGravity="fill" app:tabMode="fixed" ...
<android.support.design.widget.TextInputLayout android:hint="@string/hint_email" app:hintTextAppearance="@style/TextAppearance.Design.Hint" app:hintAnimationEnabled="true" app:errorTextAppearance="@style/TextAppearance.Design.Error" app:errorEnabled="true" ... > <EditText ... /> </android.support.design.widget.TextInputLayout>
<android.support.design.widget.FloatingActionButton android:id="@+id/fabBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|right" android:src="@drawable/ic_plus" app:fabSize="normal" />
Snackbar .make(parentLayout, R.string.snackbar_text, Snackbar.LENGTH_LONG) .setAction(R.string.snackbar_action, myOnClickListener) .show(); // Don’t forget to show!
<android.support.v4.widget.DrawerLayout android:fitsSystemWindows="true" ... > <android.support.design.widget.NavigationView xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/navigation_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:headerLayout="@layout/layout_navigation_view_header" app:menu="@menu/navigation_view_items" /> </android.support.v4.widget.DrawerLayout/>
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <group android:checkableBehavior="single"> <item android:id="@+id/navigation_item_1" android:checked="true" android:icon="@drawable/ic_action_grade" android:title="@string/navigation_item_1"/> ... </group> <item android:id="@+id/navigation_subheader" android:title="@string/navigation_subheader"> <menu> <item android:id="@+id/navigation_sub_item_1" android:icon="@drawable/ic_action_grade" android:title="@string/navigation_sub_item_1"/> ...
public class NavigationViewActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { @Override protected void onCreate(Bundle savedInstanceState) { ... NavigationView nv = (NavigationView) findViewById(R.id.navigation_view); nv.setNavigationItemSelectedListener(this); } @Override public boolean onNavigationItemSelected(MenuItem menuItem) { menuItem.setChecked(true); ... return true; } }
<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView app:layout_behavior="@string/appbar_scrolling_view_behavior" android:id="@+id/recyler_view" ... /> <android.support.design.widget.AppBarLayout android:layout_height="wrap_content" android:layout_width="match_parent"> <android.support.v7.widget.Toolbar app:layout_scrollFlags="scroll|enterAlways" ... /> </android.support.design.widget.AppBarLayout> </android.support.design.widget.CoordinatorLayout>