使用Theme.MaterialComponents.Light.NoActionBar样式时,设置Button Background无效 [英] When using Theme.MaterialComponents.Light.NoActionBar style, setting Button Background has no effect
问题描述
为了使用Chip和ChipGroup,我将应用程序样式设置为 Theme.MaterialComponents.Light.NoActionBar
int manifests.xml,然后将Button设置为"android:background" attr,但没有这样做影响!为什么?那我该怎么办?
In order to use Chip and ChipGroup, I set Application style extends Theme.MaterialComponents.Light.NoActionBar
int manifests.xml, then I set Button "android:background" attr, but it does not effect! why? and what can I do?
这是我的风格
<style name="AppBaseTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">@color/primary_material_light</item>
<item name="colorPrimaryDark">@color/header_color</item>
<item name="actionBarSize">48dp</item>
<item name="android:screenOrientation">portrait</item>
<!--<item name="buttonStyle">@style/AntButton</item>-->
<!--<item name="materialButtonStyle">@style/AntButton</item>-->
<!--<item name="android:button"></item>-->
<!--<item name="android:progressTint">@color/ffc000</item>-->
<item name="colorAccent">@color/ffc000</item>
</style>
<style name="AntButton" parent="android:Widget">
<item name="android:background">@drawable/abc_btn_default_mtrl_shape</item>
<item name="android:textAppearance">?android:attr/textAppearanceButton</item>
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">88dip</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
<!--<item name="android:colorButtonNormal">@color/white</item>-->
</style>
我试图更改buttonStyle和materialButtonStyle,但也没有效果!
I have tried to change buttonStyle and materialButtonStyle, but not effect too!
这是我的布局XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/ll_popup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/white"
android:divider="@drawable/shape_divider_05dp"
android:orientation="vertical"
android:showDividers="beginning|middle">
<!--only can use backgroundTint to change background color-->
<Button
android:id="@+id/item_popupwindows_Photo"
android:layout_width="match_parent"
android:layout_height="55dp"
android:backgroundTint="@color/white"
android:text="Pictrue"
android:textColor="@color/c_666666"
android:textSize="16sp" />
<!--background not effect !!-->
<Button
android:id="@+id/item_popupwindows_cancel"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="@color/white"
android:text="cancel"
android:textColor="@color/c_666666"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
这是结果:
因为我在APP中使用了Chip和ChipGroup,所以我必须以用户主题扩展MaterialComponents!您知道如何解决吗?请告诉我,谢谢!
Because I have used Chip and ChipGroup in APP, I have to user theme extends MaterialComponents! do you know how to resolve it ?please tell me, thanks!
在此页面中的无法使用android:来自新材质组件的带有按钮的背景,作者想要更改默认填充,但是我想更改 backgroundDrawable
,所以它对我不起作用.
in this page Can't use android:background with button from the new material components, the author wants to change the default padding, but I want to change the backgroundDrawable
, so, it does not work for me.
推荐答案
如果您想要一个真正的 Button
,但是可以像框架 Button
那样修改(而不是一个)( MaterialButton
),则可以在布局文件中显式指定框架版本.替换为:
If you want a true Button
, but one that you can modify like the framework Button
(instead of the MaterialButton
), then you can explicitly specify the framework version in your layout file. Replace this:
<Button
android:id="@+id/item_popupwindows_cancel"
... />
与此:
<android.widget.Button
android:id="@+id/item_popupwindows_cancel"
... />
这将为您提供语音提示:一个 android.widget.Button
,它应以您期望的方式进行响应.
This will give you what it says on the tin: an android.widget.Button
, which should respond to styling the way you expect.
类似地,如果您要支持库功能而不是材料组件功能,则可以使用< androidx.appcompat.widget.AppCompatButton>
.
Similarly, you could use a <androidx.appcompat.widget.AppCompatButton>
if you want support library features but not material components features.
这篇关于使用Theme.MaterialComponents.Light.NoActionBar样式时,设置Button Background无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!