我目前正在开始使用 Material 组件主题。 Getting Started指南提到了这些主题:
Theme.MaterialComponents
Theme.MaterialComponents.NoActionBar
Theme.MaterialComponents.Light
Theme.MaterialComponents.Light.NoActionBar
Theme.MaterialComponents.Light.DarkActionBar
Theme.MaterialComponents.DayNight
Theme.MaterialComponents.DayNight.NoActionBar
Theme.MaterialComponents.DayNight.DarkActionBar
虽然没有对它们的描述。我在哪里可以找到有关这些主题的更多详细信息,或者有人可以在答案中解释它们吗?举个例子:
[..].NoActionBar
?如果我不想要操作栏,我不会将它包含在我的布局文件中,所以我真的不明白。 Theme.MaterialComponents
?或者我会一直使用 Theme.MaterialComponents.Light
或 Theme.MaterialComponents.DayNight
? 最佳答案
我敢肯定,我无法详尽地回答您的所有问题,但我会分享一些想法,也许它会让您更进一步:
What means [..].NoActionBar?
如果您不希望运行时添加
ActionBar
,则应使用以“.NoActionBar”结尾的主题。到Activity
,可能是因为您使用了 Toolbar
.例如,如果您选择 Theme.MaterialComponents.Light
并使用 Toolbar
同样,您会注意到现在您的应用程序将使用两个 ActionBar
呈现s请注意,如果某个主题被称为“MyTheme”,那么一个主题以“MyTheme”为前缀。将继承“MyTheme”的所有内容。所以
Theme.MaterialComponents.Light.NoActionBar
与 Theme.MaterialComponents.Light
几乎相同除了 ActionBar
.所以如果你真的不想要任何
ActionBar
你应该选择.NoActionBar
版本并且不在布局文件中包含代理项 ( Toolbar
)。What do these themes define? Only colors? Text style? Font family?
他们这样做,但他们也定义了大小、边距和行为。除此之外,其中一些对某些小部件具有特殊的样式组合(例如
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
用于 TextInputLayout
)要深入了解主题会影响哪些属性,您可以查看 themes_material.xml 的来源
When would I use only Theme.MaterialComponents? Or would I always use Theme.MaterialComponents.Light or Theme.MaterialComponents.DayNight?
由于
Theme.MaterialComponents
是 Theme.MaterialComponents.Light
的父主题, 他们有很多共同点。主要区别在于第一个假设您的应用程序将具有深色背景(因此文本应为白色),而第二个将具有黑色文本并假设您的应用程序的背景将是浅色的。通常,人们会尝试使用某个主题作为模板,然后可以/必须对其进行自定义 - 例如使用特殊的强调色。
How do these themes look like?
您可以通过在您自己的小型示例应用程序中从一个切换到另一个来获得一个大致的概念。
确实没有单一的信息来源(又名安卓主题圣经)。您已经找到material.io , 但也许 Styles and Themes来自 developer.android.com 的部分或此博客文章 DayNight — Adding a dark theme to your app会散发出更多的光芒。
关于android - Material Components 主题的描述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60063644/