android - 材料设计排版和小吃店
问题描述
根据https://material.io/develop/android/theming/typography/,我一直在通过修改 textAppearanceX 属性来自定义我的应用程序的样式。有谁知道要自定义哪个属性来设置应用程序的 Snackbars 样式或记录在哪里?
谢谢你。
解决方案
使用材料组件库,您可以textAppearance
通过应用程序主题自定义文本和按钮使用的内容:
只需使用snackbarButtonStyle
andsnackbarTextViewStyle
属性在应用程序中全局定义:
<style name="AppTheme" parent="Theme.MaterialComponents.*">
<!-- Style to use for action button within a Snackbar in this theme. -->
<item name="snackbarButtonStyle">@style/Custom.TextButton.Snackbar</item>
<!-- Style to use for message text within a Snackbar in this theme. -->
<item name="snackbarTextViewStyle">@style/Custom.Snackbar.TextView</item>
....
</style>
然后对于按钮android:textAppearance
,您可以定义应用属性的自定义样式
<style name="Custom.TextButton.Snackbar" parent="@style/Widget.MaterialComponents.Button.TextButton.Snackbar">
<item name="android:textAppearance">@style/snackbar_button_textappearance</item>
</style>
这只是一个例子:
<style name="snackbar_button_textappearance" parent="@style/TextAppearance.MaterialComponents.Button">
<item name="android:textStyle">italic</item>
</style>
对于文本,您可以执行类似的操作:
<style name="Custom.Snackbar.TextView" parent="@style/Widget.MaterialComponents.Snackbar.TextView">
<item name="android:textAppearance">......</item>
</style>
请注意:
snackbarButtonStyle
属性需要版本1.1.0snackbarTextViewStyle
属性需要版本1.2.0。
推荐阅读
- sql - 基于两次每日更新列
- java - 如何从 Codename one 的 ConnectionRequest 获得来自 http 和不安全 https 站点的响应?Android 10 中的 http 和 https 问题(在 Google Pixel 中)
- java - 什么 (s.charAt(low) != s.charAt(high)) {" and " int high = s.length() - 1;
- c++ - C++ DetourAttach
- php - 无法连接到 docker-compose 中的数据库服务器(php 和 MariaDB)
- java - 启动 java 方法时在我的 mac 上获取 NSException
- android - 相机应用的全景解决方案
- javascript - multer/filepond 上传返回未定义
- reactjs - Redux 对于 React 和 React Native 是一样的吗?
- asp.net - HTTP 到 HTTPS 不适用于我的 asp.net 网站