material theme 自定义_Material Theme

本文详细介绍了Android 5.0引入的Material Theme,包括三种内置风格:深色、浅色和带有深色操作栏的浅色风格。Material Theme不仅用于系统UI,也用于应用程序。你可以通过自定义颜色属性来创建自己的主题,例如改变应用栏和UI控件的颜色。此外,文章还展示了如何在应用级别和活动级别配置主题,并提供了在Android 5.0及更低版本中实现兼容性的方法。
摘要由CSDN通过智能技术生成

Material ThemeMaterial Theme

03/01/2018

本文内容

材料主题 是一种用户界面样式,用于确定从 Android 5.0 (棒糖形) 开始的视图和活动的外观和感觉。Material Theme is a user interface style that determines the look and feel of views and activities starting with Android 5.0 (Lollipop). 材料主题内置于 Android 5.0 中,因此它由系统 UI 和应用程序使用。Material Theme is built into Android 5.0, so it is used by the system UI as well as by applications. 对于系统范围内的外观选项,用户可从 "设置" 菜单动态选择的 "材料" 主题不是 "主题"。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 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 提供三种材料主题风格:Android provides three Material Theme flavors:

Theme.Material–深色版本的材料主题; 这是 Android 5.0 中的默认风格。Theme.Material – Dark version of Material Theme; this is the default flavor in Android 5.0.

Theme.Material.Light–材料主题的轻型版本。Theme.Material.Light – Light version of Material Theme.

Theme.Material.Light.DarkActionBar–材料主题的轻型版本,但具有深色操作栏。Theme.Material.Light.DarkActionBar – Light version of Material Theme, but with a dark action bar.

此处显示了这些材料主题风格的示例:Examples of these Material Theme flavors are displayed here:

372ff75b423eb056aecc7d0f5f1739c9.png372ff75b423eb056aecc7d0f5f1739c9.png

可以从材料主题派生,以创建自己的主题,并覆盖部分或全部颜色属性。You can derive from Material Theme to create your own theme, overriding some or all color attributes. 例如,你可以创建一个从派生的主题 Theme.Material.Light ,但会覆盖应用栏颜色以匹配品牌的颜色。For example, you can create a theme that derives from Theme.Material.Light, but overrides the app bar color to match the color of your brand. 您还可以设置各个视图的样式;例如,可以创建具有更多圆角的 CardView 样式,并使用较暗的背景色。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 an app. 例如,在上面的屏幕截图中,一个应用对每个活动使用不同的主题来演示内置的配色方案。In the above screenshots, for example, a single app uses a different theme for each activity to demonstrate the built-in color schemes. 单选按钮会将应用切换到不同的活动,因此会显示不同的主题。Radio buttons switch the app to different activities, and, as a result, display different themes.

由于仅 Android 5.0 及更高版本支持材料主题,因此你不能使用它 (或从材料主题) 派生的自定义主题,以便将应用程序应用于早期版本的 Android。Because 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. 但是,你可以将应用配置为使用 Android 5.0 设备上的材料主题,并在较早版本的 Android 上运行时适当地回退到前面的主题 (请参阅本文的 " 兼容性 " 部分以了解详细信息) 。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

若要在基于 Xamarin 的应用中使用新的 Android 5.0 材料主题功能,需要满足以下要求:The following is required to use the new Android 5.0 Material Theme features in Xamarin-based apps:

Xamarin.Android – 必须安装和配置 Xamarin xamarin 4.20 或更高版本,并且必须安装 Visual Studio 或 Visual Studio for Mac。Xama

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值