深色主题中的 TextButton 默认颜色
尝试更改我的 Android 应用程序中所有 TextButtons 的默认颜色和材质。我看到我可以设置“materialButtonStyle”和“materialButtonOutlinedStyle”的样式。但是,我没有看到文本按钮的属性,可能类似于“materialButtonTextStyle”
<style name="AppTheme" parent="Theme.MaterialComponents">
<item name="materialButtonStyle">@style/myButton</item>
<item name="materialButtonOutlinedStyle">@style/myButtonOutlined</item>
</style>
示例按钮:
<Button
android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:text="Text Button" />
是否可以全局更改所有材质文本按钮的样式?
编辑:从主题按钮材质文档中尝试过此操作。
<style name="AppTheme" parent="Theme.MaterialComponents">
<item name="borderlessButtonStyle">@style/Widget.App.Button.TextButton</item>
</style>
<style name="Widget.App.Button.TextButton" parent="Widget.MaterialComponents.Button.TextButton">
<item name="materialThemeOverlay">@style/ThemeOverlay.App.Button.TextButton</item>
</style>
<style name="ThemeOverlay.App.Button.TextButton" parent="">
<item name="colorPrimary">@color/md_purple_600</item>
</style>
但是仍然没有为所有文本按钮设置文本颜色样式。
Trying to change the default color for all TextButtons in my Android app w/ material. I see that I can style a "materialButtonStyle" and "materialButtonOutlinedStyle". However I do not see an attribute for a text button, possible something like "materialButtonTextStyle"
<style name="AppTheme" parent="Theme.MaterialComponents">
<item name="materialButtonStyle">@style/myButton</item>
<item name="materialButtonOutlinedStyle">@style/myButtonOutlined</item>
</style>
Example button:
<Button
android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:text="Text Button" />
Is it possible to change the style globally for all material text buttons?
EDIT: Tried this from the theming-buttons material docs.
<style name="AppTheme" parent="Theme.MaterialComponents">
<item name="borderlessButtonStyle">@style/Widget.App.Button.TextButton</item>
</style>
<style name="Widget.App.Button.TextButton" parent="Widget.MaterialComponents.Button.TextButton">
<item name="materialThemeOverlay">@style/ThemeOverlay.App.Button.TextButton</item>
</style>
<style name="ThemeOverlay.App.Button.TextButton" parent="">
<item name="colorPrimary">@color/md_purple_600</item>
</style>
However still not styling the text color for all text buttons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 buttons -baterons -material Design 文档文档
textbutton
默认样式主题属性?atter/borderlessbuttonStyle
可以在Apptheme中使用该样式在所有材料文本按钮上全球更改样式。要为所有文本键的全球更改文本颜色:
1。定义
borderlessButtonStyle
在灯光和夜晚中的属性如下:2。在每个TextButton xml xml布局中定义样式
style = style =“? attr/borderlessbuttonStyle“
如下:和文本颜色将在全球更改为
colorprimary
,该在光/夜主题中定义。您可以为其他材料按钮样式实现相同
按照相同的方式, 上方全局属性:
下面是光模式下每个按钮样式的示例结果:
及以下是夜间模式下每个按钮样式的示例结果:
As per the Buttons -Material design documentation the
TextButton
has a default style theme attribute?attr/borderlessButtonStyle
which can be used in the AppTheme to change the style globally for all material text buttons.To change the Text Colour globally for all TextButtons:
1.Define the
borderlessButtonStyle
attribute in the Light and Night AppTheme like the below:2.In every TextButton xml layout define the style
style="?attr/borderlessButtonStyle"
like the below:And the Text colour will be changed globally based to the
colorPrimary
which is defined in Light/Night Theme.Following the same way you can achieve the same for the other Material Button Styles like
OutlinedButton
and the defaultButton
like:And each
Button
listens to the above global attributes:Below is a sample result for each Button Style in Light mode:
And below is a sample result for each Button Style in Night mode:
如您所见,从
textbuttoncolors
,使用材料的主要颜色
作为默认内容颜色。为了实现目标,如果您不更改原色,则可以定义自定义主题并覆盖文本按钮的样式。
As you can see from
textButtonColors
, TextButton use the primary color of yourMaterialTheme
as default content color.To achieve your goal, if you don't change your primary color, you can define a custom theme and override the style of your text buttons.
在标题中,它说您想为黑暗主题定义 textcolor 。您是否在
value-night
中定义了主题,因此如果手机处于黑暗模式,您的应用程序将采用这些值。In the title it says you want to define textColor for a dark theme. Did you define the theme in
values-night
so your app will take these values if the phone is in dark mode.