Why should I use material design

Material DesignMaterial Theme

  • 8 minutes to read

The material Design is a user interface style that defines the appearance of views and activities, starting with Android 5.0 (Lollipop).Material theme is a user interface style that determines the look and feel of views and activities starting with Android 5.0 (Lollipop). The Material Design is built into Android 5.0 so that it is used by the system user interface as well as by applications. Material Theme is built into Android 5.0, so it is used by the system UI as well as by applications. The Material Design is not a "design" in the sense of a system-wide display option that a user can dynamically select from the "Settings" menu. Material Theme is not a "theme" in the sense of a system-wide appearance option that a user can dynamically choose from a settings menu. Rather, Material Design can be viewed as a set of related, built-in basic styles that you can use to customize the look and feel of your app Rather, Material Theme can be thought of as a set of related built-in base styles that you can use to customize the look and feel of your app.

Android provides three Material Design flavors: Android provides three Material Theme flavors:

  • –Dark version of Material Theme; This is the default configuration in Android 5.0. - Dark version of Material Theme; this is the default flavor in Android 5.0.

  • –Light version of the material design. - Light version of Material Theme.

  • –Light version of the Material Design, but with a dark action bar. - Light version of Material Theme, but with a dark action bar.

Examples of these Material Theme flavors are displayed here:

You can derive from Material Theme to create your own theme, overriding some or all color attributes. b. For example, you can create a theme that derives from, but overrides the app bar color to match the color of your brand can also format individual views. For example, you can create a style for CardView that has more rounded corners and uses a darker background color. You can also style individual views; for example, you can create a style for CardView that has more rounded corners and uses a darker background color.

You can use a single theme for an entire app, or you can use different themes for different screens (activities) in the above screenshots, for example, a single app uses a different theme for each activity to demonstrate the built- Radio buttons switch the app to different activities, and, as a result, display different themes.

Since Material Design is only supported on Android 5.0 and above, you cannot use it (or a custom design derived from Material Design) to use the app to run on previous versions of Android Material Theme is supported only on Android 5.0 and later, you cannot use it (or a custom theme derived from Material Theme) to theme your app for running on earlier versions of Android. However, you can configure your APP to use the Material Design on Android 5.0 devices, and revert to an earlier theme when running on older versions of Android (see the compatibility section in this article for more information). However, you can configure your app to use Material Theme on Android 5.0 devices and gracefully fall back to an earlier theme when it runs on older versions of Android (see the Compatibility section of this article for details).

Requirements Requirements

The following is required to use the new Android 5.0 Material Theme features in Xamarin-based apps:

  • Xamarin. Android - xamarin. Android 4.20 or higher must be installed and configured with either Visual Studio or Visual Studio for Mac.Xamarin.Android - Xamarin.Android 4.20 or later must be installed and configured with either Visual Studio or Visual Studio for Mac.

  • Android SDK - Android 5.0 (API 21) or higher must be installed via the Android SDK manager.Android SDK - Android 5.0 (API 21) or later must be installed via the Android SDK Manager.

  • Java JDK 1.8 - JDK 1.7 can be used if you are specifically targeting API level 23 and earlier.Java JDK 1.8 - JDK 1.7 can be used if you are specifically targeting API level 23 and earlier. JDK 1.8 is available in Oracle. JDK 1.8 is available from Oracle.

To learn how to configure an Android 5.0 app project, see Setting Up an Android 5.0 Project.

Using the Built-in Themes

The easiest way to use Material Theme is to configure your app to use a built-in theme without customization If you don't want to explicitly configure a theme, your app will default to (the dark theme). You can configure a theme at the activity level. If your app has only one activity, you can configure a theme at the activity level. If your app has multiple activities, you can configure an application-level theme so that they all have the same theme Activities, or you can assign different themes to different activities. If your app has multiple activities, you can configure a theme at the application level so that it uses the same theme across all activities, or you can assign different themes to different activities. The following sections explain how to configure themes at the app level and at the activity level.

Theming an Application

To configure an entire application to use a Material Design configuration, set the attribute of the application node in AndroidManifest.xml To configure an entire application to use a Material Theme flavor, set the attribute of the application node in AndroidManifest.xml to one of the following:

  • –Dark design. - Dark theme.

  • –Bright design. - Light theme.

  • –Light design with a dark action bar. - Light theme with dark action bar.

The following example uses the myapp configured to use the Design Light: The following example configures the application MyApp to use the light theme:

Alternatively, you can use the application attribute in AssemblyInfo.cs (or Properties.csAlternatively, you can set the application attribute in AssemblyInfo.cs (or Properties.csExample: For example:

When the application design is set to, any activity in myapp When the application theme is set to, every activity in MyApp will be displayed using.

Theming an Activity

To theme an activity, you add a setting to the attribute above your activity declaration and assign to the Material The following example themes an activity with:

Other activities in this app will use the default dark color scheme (or, if configured, the application theme setting) .

Using Custom Themes

You can enhance your brand by creating a custom theme that styles your app with your brand's colors. To create a custom theme, you define a new style that derives from a built-in Material Theme flavor, overriding the color attributes that you want to change. For example, you can define a custom theme that derives from and changes the screen background color to beige instead of white.

Material Theme exposes the following layout attributes for customization:

  • –The color of the APP bar. - The color of the app bar.

  • –The color of the status bar and the contextual app bars. This is usually a dark version of. - The color of the status bar and contextual app bars; this is normally a dark version of.

  • –The color of UI controls; b. Edit check boxes, option fields and text fields. - The color of UI controls such as check boxes, radio buttons, and edit text boxes.

  • –The color of the screen background. - The color of the screen background.

  • –The color of the UI text in the APP bar. - The color of UI text in the app bar.

  • –The color of the status bar. - The color of the status bar.

  • –The color of the navigation bar. - The color of the navigation bar.

These screen areas are labeled in the following diagram:

By default, is set to the value of. You can set to a solid color, or you can set it to to make the status bar transparent. The navigation bar can also be made transparent by setting to.

Creating a Custom App Theme

You can create a custom app design by editing files in the resources You can create a custom app theme by creating and modifying files in the Resources folder of your app project. To style your app with a custom theme, use the following steps:

  • Create a colors.xml File in Resources / values - You use this file to define the custom design colors. Create a colors.xml file in Resources / values - you use this file to define your custom theme colors. For example, you can put the following code in colors.xml To get you started: For example, you can paste the following code into colors.xml to help you get started:
  • Modify this example file to define the names and color codes for color resources that you will use in your custom theme.

  • Create a folder " Resources / Values-V21 ". Create a Resources / values-v21 folder, create a styles.xml -File: In this folder, create a styles.xml file:

    Note that the Resources / values ​​V21 especially for Android 5.0, - older versions of Android, do not read any files in this folder. Note that Resources / values-v21 is specific to Android 5.0 - older versions of Android will not read files in this folder.

  • Add a node to styles.xml and define a node with the name of the custom theme styles.xml and define a node with the name of your custom theme. For example, here is a styles.xml File that mycustomtheme defined (derived from the integrated design style): For example, here is a styles.xml file that defines MyCustomTheme (derived from the built-in theme style):

  • At this point an APP shows that mycustomtheme uses the share design without any adjustments to: At this point, an app that uses MyCustomTheme will display the stock theme without customizations:

  • Add styles.xml Add color customizations to styles.xml by defining the colors of layout attributes that you want to change. b. Want to change the color of the app bar in and change the color of UI controls in, add styles.xml that click in colors.xmlFor example, to change the app bar color to and change the color of UI controls to, add color overrides to styles.xml that refer to color resources configured in colors.xml:

After these changes are made, an app showing the mycustomtheme uses one color of the APP bar in and UI controls in, but uses the color scheme in all other places: With these changes in place, an app that uses MyCustomTheme will display an app bar color in and UI controls in, but use the color scheme everywhere else:

In this example, mycustomtheme Colors off for the background color, the status bar and the text colors, but the color of the app bar changed to and the color of the options field set to. MyCustomTheme borrows colors from for the background color, status bar, and text colors, but it changes the color of the app bar to and sets the color of the radio button to.

Creating a Custom View Style

Android 5.0 also makes it possible for you to style an individual view colors.xml and styles.xml (as described in the previous section), you can styles.xmladd a view style colors.xml other styles.xml (as described in the previous section), you can add a view style to styles.xmlTo style an individual view, use the following steps:

  • Edit it Resources / values ​​V21 / styles.xml , and add a node with the name of your custom view style. Edit Resources / values-v21 / styles.xml and add a node with the name of your custom view style. Set the custom color attributes for your view within this node. b. To create a custom map view style that has more rounded corners and uses a map background color, add a node styles.xml (inside the node) and configure the background color and the corner radius: For example, to create a custom CardView style that has more rounded corners and uses as the card background color, add a node to styles.xml (inside the node) and configure the background color and corner radius:
  • In your layout, set the attribute for that view to match the custom style name that you chose in the previous step. Example: For example:

The following screenshot provides an example of the default (shown on the left) compared to one formatted with the custom theme (shown on the right): as compared to a that has been styled with the custom theme (shown on the right):

In this example, the custom is displayed with the background color and an 18dp corner radius.

CompatibilityCompatibility

To style your app so that it uses Material Theme, please follow these steps to format your app so that it uses Material Design on Android 5.0, but automatically uses a backward-compatible style for older Android versions: To style your app so that it uses Material Theme on Android 5.0 but automatically reverts to a downward-compatible style on older Android versions, use the following steps:

  • Define a custom design in Resources / Values ​​V21 / styles.xml , which is derived from a Material Design Style. Define a custom theme in Resources / values-v21 / styles.xml that derives from a Material Theme style.
  • Define a custom design in Resources / values ​​/ styles.xml which is derived from an older theme but uses the same theme name as above Resources / values ​​/ styles.xml that derives from an older theme, but uses the same theme name as above.
  • Configure in AndroidManifest.xmlYour APP with the custom design name AndroidManifest.xml, configure your app with the custom theme name.
  • Alternatively, you can style a specific activity using your custom theme:

If your design uses colors that are in a colors.xml File, make sure you put that file in Resources / values (instead of Resources / Values-V21) so that both versions of the custom theme have access to their color definitions colors.xml file, be sure to place this file in Resources / values (rather than Resources / values-v21) so that both versions of your custom theme can access your color definitions.

If your app is running on an Android 5.0 device, the in Resources / Values-V21 / styles.xmlWhen your app runs on an Android 5.0 device, it will use the theme definition specified in Resources / values-v21 / styles.xmlIf this app is running on older Android devices, it will be automatically redirected to the in Resources / Values ​​/ styles.xmlWhen this app runs on older Android devices, it will automatically fall back to the theme definition specified in Resources / values ​​/ styles.xml.

For more information about theme compatibility with older Android versions, see Alternate Resources.

SummarySummary

This article introduced the new Material Theme user interface style included in Android 5.0 (Lollipop). The three built-in Material Design Described variants that you can use to format your app. It described the three built-in Material Theme flavors that you can use to style your app, it explained how to create a custom theme for branding your app, and it provided an example of how to theme an individual view. Finally, this article explained how to use Material Design in your app while maintaining compatibility with older versions of Android. Finally, this article explained how to use Material Theme in your app while maintaining downward compatibility with older versions of Android.

Related Links