Android MaterialButton样式未更改
我正在尝试使用Android MaterialButton样式未更改,android,android-studio,material-design,material-theme,Android,Android Studio,Material Design,Material Theme,我正在尝试使用实现'com.google.android.material:material:1.0.0'提供的新样式来设置材质按钮的样式 library。问题是按钮的样式设置不正确。例如,我有两个不同的活动,使用完全相同的主题,按钮的代码完全相同,但on拒绝使用正确的样式,在Android预览屏幕上看起来是正确的,但在实际的应用程序中不是 此外,我还通过设置style=“mybuttonstylewhere”手动覆盖一组按钮的样式,但这也会被忽略。这是非常令人沮丧的,所以我希望有人能帮助我 样
实现'com.google.android.material:material:1.0.0'提供的新样式来设置材质按钮的样式
library。问题是按钮的样式设置不正确。例如,我有两个不同的活动,使用完全相同的主题,按钮的代码完全相同,但on拒绝使用正确的样式,在Android预览屏幕上看起来是正确的,但在实际的应用程序中不是
此外,我还通过设置style=“mybuttonstylewhere”
手动覆盖一组按钮的样式,但这也会被忽略。这是非常令人沮丧的,所以我希望有人能帮助我
样式-v11
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyMaterialTheme.Base" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorPrimaryDark</item>
</style>
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="colorPrimary">#364c70</item>
<item name="actionMenuTextColor">@android:color/white</item>
</style>
<style name="WhiteButtons" parent="Widget.MaterialComponents.Button">
<item name="android:background">#ffff</item>
<item name="android:textColor">#000</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyMaterialTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>
<style name="MyMaterialTheme.Base" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorPrimaryDark</item>
</style>
</resources>
符合事实的
错误的
@颜色/原色
@颜色/原色暗
@颜色/原色暗
#364c70
@android:彩色/白色
#ffff
#000
样式-v21
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyMaterialTheme.Base" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorPrimaryDark</item>
</style>
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="colorPrimary">#364c70</item>
<item name="actionMenuTextColor">@android:color/white</item>
</style>
<style name="WhiteButtons" parent="Widget.MaterialComponents.Button">
<item name="android:background">#ffff</item>
<item name="android:textColor">#000</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyMaterialTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>
<style name="MyMaterialTheme.Base" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorPrimaryDark</item>
</style>
</resources>
符合事实的
符合事实的
符合事实的
@android:过渡/移动
@android:过渡/移动
符合事实的
错误的
@颜色/原色
@颜色/原色暗
@颜色/原色暗
风格
<resources>
<style name="MyMaterialTheme.Base" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorPrimaryDark</item>
</style>
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="colorPrimary">#364c70</item>
<item name="actionMenuTextColor">@android:color/white</item>
</style>
<style name="WhiteButtons" parent="Widget.MaterialComponents.Button">
<item name="android:background">#ffff</item>
<item name="android:textColor">#000</item>
</style>
</resources>
符合事实的
错误的
@颜色/原色
@颜色/原色暗
@颜色/原色暗
#364c70
@android:彩色/白色
#ffff
#000
用于按钮的代码
<com.google.android.material.button.MaterialButton
android:id="@+id/get_suggestions"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="@dimen/_65sdp"
android:layout_height="wrap_content"
android:layout_marginStart="163dp"
android:layout_marginTop="83dp"
android:layout_marginEnd="163dp"
android:layout_marginBottom="219dp"
android:text="SEARCH"
android:textSize="@dimen/_9sdp"
app:cornerRadius="100dp" />
不想让自己看起来像那样
您发布的样式毫无意义
- 您正在显示
和工具栏样式
样式,但您没有在任何地方使用它们白色按钮
- 其中一个文件中有
(与MyMaterialTheme
相反);我希望您不会期望它被MyMaterialTheme.Base
自动继承,因为指定MyMaterialTheme.Base
会覆盖点符号继承parent
- 这三个文件的
的内容相同;为什么要在三个地方指定它呢MyMaterialTheme.Base
MaterialButton
小部件(除了colorPrimary
)。所以很难确切知道你的问题在哪里
总之,MaterialButton
支持的属性列表在中提供。值得注意的是,android:background
不受MaterialButton
支持。发件人:
不要使用android:background
属性MaterialButton
管理其自己的后台绘图,设置新的后台意味着MaterialButton
无法再保证它引入的新属性将正常工作。如果更改了默认背景,MaterialButton
无法保证定义良好的行为
我怀疑您看到的是两个屏幕上不同的colorPrimary
定义的组合,以及android:background
不受支持的事实
如果要手动覆盖按钮的背景色,请使用
标记上的app:backgroundTint
属性。如果要在
标记中指定,则它不使用命名空间:
<item name="backgroundTint">@color/your_background_color</item>
@color/你的背景色
您发布的样式毫无意义
- 您正在显示
和工具栏样式
样式,但您没有在任何地方使用它们白色按钮
- 其中一个文件中有
(与MyMaterialTheme
相反);我希望您不会期望它被MyMaterialTheme.Base
自动继承,因为指定MyMaterialTheme.Base
会覆盖点符号继承parent
- 这三个文件的
的内容相同;为什么要在三个地方指定它呢MyMaterialTheme.Base
MaterialButton
小部件(除了colorPrimary
)。所以很难确切知道你的问题在哪里
总之,MaterialButton
支持的属性列表在中提供。值得注意的是,android:background
不受MaterialButton
支持。发件人:
不要使用android:background
属性MaterialButton
管理其自己的后台绘图,设置新的后台意味着MaterialButton
无法再保证它引入的新属性将正常工作。如果更改了默认背景,MaterialButton
无法保证定义良好的行为
我怀疑您看到的是两个屏幕上不同的colorPrimary
定义的组合,以及android:background
不受支持的事实
如果要手动覆盖按钮的背景色,请使用
标记上的app:backgroundTint
属性。如果要在
标记中指定,则它不使用命名空间:
<item name="backgroundTint">@color/your_background_color</item>
@color/你的背景色
谢谢,我会做一些更改,但我正在使用“style=“@style/Widget.MaterialComponents.Button.OutlineButton”作为我的一个按钮,它实际上看起来不像是要在android预览中使用的