| Start |
|---|
| Adding a Toolbar A Set the theme for your app to one that does **not** have an `ActionBar`. To do that, edit your **styles.xml** file under `res/values`, and set a `Theme.AppCompat` theme. You can also use Below the After performing the above steps, you can use the For example, you can set the title as shown below: For example, you can also set title and background color as shown below: |
| Buttons styled with Material Design The AppCompat Support Library (opens new window) defines several useful styles for Buttons (opens new window), each of which extend a base In this case the accent color is pink. Colored Button: `@style/Widget.AppCompat.Button.Colored` If you want to customize the background color without changing the accent color in your main theme you can create a custom theme (extending the Define the theme in |
| Adding a FloatingActionButton (FAB) In the material design, a Floating action button (opens new window) represents the primary action in an Activity. Make sure the following dependency is added to your app's build.gradle file under dependencies: Now add the where the By default, the background color of your Here are properties which you can use to customize the
You can find more examples about FAB here (opens new window). |
| RippleDrawable Ripple touch effect was introduced with material design in Android 5.0 (API level 21) and the animation is implemented by the new RippleDrawable (opens new window) class. Drawable that shows a ripple effect in response to state changes. The anchoring position of the ripple for a given state may be specified by calling In general, ripple effect for regular buttons works by default in API 21 and above, and for other touchable views, it can be achieved by specifying: for ripples contained within the view or: for ripples that extend beyond the view's bounds. For example, in the image below,
(Image courtesy: http://blog.csdn.net/a396901990/article/details/40187203 (opens new window) ) You can achieve the same in code using: Ripples can also be added to a view using the If you want to customize the ripple effect into a view,
you need to create a new Here are few examples: Example 1: An unbounded ripple Example 2: Ripple with mask and background color If there is Example: Example 3: Ripple on top a drawable resource Usage:
To attach your ripple xml file to any view, set it as background as following (assuming your ripple file is named Selector: The ripple drawable can also be used in place of color state list selectors if your target version is v21 or above (you can also place the ripple selector in the In this case, the color of the default state of your view would be white and the pressed state would show the ripple drawable. Point to note: Using To change just the ripple color, you can customize the color and then use this theme in your activities, etc. The effect would be like the image below: (Image courtesy: http://blog.csdn.net/a396901990/article/details/40187203 (opens new window) ) |
| Adding a TabLayout TabLayout (opens new window) provides a horizontal layout to display tabs, and is commonly used in conjunction with a ViewPager (opens new window). Make sure the following dependency is added to your app's Now you can add items to a TabLayout in your layout using the TabItem (opens new window) class. For example: Add an Tabs can also be added/removed from the
These can also be applied in XML: Note: the The tab indicator color is the accent color defined for your Material Design theme. Then you can apply the style to the view using: |
| Bottom Sheets in Design Support Library Bottom sheets (opens new window) slide up from the bottom of the screen to reveal more content. Make sure the following dependency is added to your app's build.gradle file under dependencies: Persistent Bottom SheetsYou can achieve a Persistent Bottom Sheet (opens new window) attaching a Then in your code you can create a reference using: You can set the state of your BottomSheetBehavior using the setState() (opens new window) method: You can use one of these states: Further to open or close the BottomSheet on click of a View of your choice, A Button let's say, here is how to toggle the sheet behavior and update view. But And if you only want your Bottom Sheet to be visible only in COLLAPSED and EXPANDED mode toggles and never HIDE use: Bottom Sheet DialogFragmentYou can also display a BottomSheetDialogFragment (opens new window) in place of a View in the bottom sheet. To do this, you first need to create a new class that extends BottomSheetDialogFragment. Within the Finally, you can call show() on an instance of your Fragment to display it in the bottom sheet. You can find more details in the dedicated topic (opens new window) |
| Apply an AppCompat theme The AppCompat support library provides themes to build apps with the Material Design specification (opens new window). A theme with a parent of The first step is to customize your theme’s color palette (opens new window) to automatically colorize your app. Instead of You can customize the theme with your own colours. Good choices are in the Material design specification colour chart (opens new window), and Material Palette (opens new window). The "500" colours are good choices for primary (blue 500 in this example); choose "700" of the same hue for the dark one; and an a shade from a different hue as the accent colour. The primary colour is used for your app's toolbar and its entry in the overview (recent apps) screen, the darker variant to tint the status bar, and the accent colour to highlight some controls. After creating this theme, apply it to your app in the You can also apply themes to individual Views using or a |
| Add a Snackbar One of the main features in Material Design is the addition of a Snackbars contain a single line of text directly related to the operation performed. They may contain a text action, but no icons. Toasts are primarily used for system messaging. They also display at the bottom of the screen, but may not be swiped off-screen. Toasts can still be used in Android to display messages to users, however if you have decided to opt for material design usage in your app, it is recommended that you actually use a snackbar. Instead of being displayed as an overlay on your screen, a Here is how it is done: As for the length of time to show the
You can also add dynamic features to your Implementing the This is how to define a The For more information about about the |
| How to use TextInputLayout Make sure the following dependency is added to your app's Show the hint from an EditText as a floating label when a value is entered. For displaying the password display eye icon with TextInputLayout, we can make use of the following code: where
You can find more details and examples in the dedicated topic (opens new window). |
| Add a Navigation Drawer Navigation Drawers (opens new window) are used to navigate to top-level destinations in an app. Make sure that you have added design support library in your Next, add the Now, if you wish, create a header file that will serve as the top of your navigation drawer. This is used to give a much more elegant look to the drawer. It is referenced in the To automatically populate your navigation drawer with material design-compliant navigation items, create a menu file and add items as needed. Note: while icons for items aren't required, they are suggested in the Material Design specification (opens new window). To separate items into groups, put them into a Now that the layout is done, move on to the You can now do whatever you want in the header view of the The header view behaves like any other You can find more details and examples in the dedicated topic (opens new window). RemarksAlso see the original Android blog post introducing the Design Support Library (opens new window) Official Documentation https://developer.android.com/design/material/index.html (opens new window) Guidelines for Material Design https://material.io/guidelines (opens new window) Other design resources and libraries |
Read Article
https://develop.horje.com/learn/1434/reference