在gradle中添加appcompat-v7不会将布局视图自动切换到AppCompat版本

问题描述 投票:0回答:1

我需要在棒棒糖前按钮和棒棒糖后按钮上使用相同的外观,并且我正在使用colorButtonNormal属性修改按钮颜色。

我正在为我的应用使用此主题:<style name="AppTheme" parent="Theme.AppCompat.Light">

由于我在所有android版本中都需要相同的外观,所以我在gradle中这样做:

implementation 'com.android.support:appcompat-v7:28.0.0'

正如文档中所提到的,只需添加该行,即可将xml布局中的所有小部件转换为这些小部件的appcompat版本,以在旧android版本中显示与现代android版本相同的外观。

AppCompat版本的Button必须能够访问xml中的此属性:

<Button
    app:backgroundTint="@color/unpressed2">
</Button>

但是出现问题是因为忽略了它。而且,如果我将xml小部件强制转换为AppCompat版本,则可以完美运行:

<android.support.v7.widget.AppCompatButton
    app:backgroundTint="@color/unpressed2">
</android.support.v7.widget.AppCompatButton>

为什么添加实现'com.android.support:appcompat-v7:28.0.0'不会自动将我所有的Button小部件更改为android.support.v7.widget.AppCompatButton小部件?

android xml android-layout android-xml android-appcompat
1个回答
0
投票

您需要使用AppCompatActivity才能在xml布局中使用AppCompat widgets

© www.soinside.com 2019 - 2024. All rights reserved.