【发布时间】:2021-05-01 21:37:32
【问题描述】:
使用 AppCompat 并使用 min sdk 版本 21,我尝试使用 ChipDrawable 在 TextEdit 中的电子邮件地址列表中使用,并使用以下方法创建该 ChipDrawable:
ChipDrawable chip = ChipDrawable.createFromResource(getApplicationContext(), R.xml.email_chip);
使用这个 xml:
<?xml version="1.0" encoding="utf-8"?>
<chip xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:chipBackgroundColor="?colorAccent"
app:closeIconEnabled="true"
app:closeIconTint="@android:color/white" />
我的主题使用Theme.MaterialComponents.DayNight.DarkActionBar(我也尝试过Theme.MaterialComponents.DayNight.DarkActionBar.Bridge)
但我总是收到这个错误:
The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
我尝试了在 stackoverflow 上找到的所有内容,但没有太大帮助。
这是我的风格
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Mareu" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">
<!-- Primary brand color. -->
<item name="colorPrimary">#4E92DF</item>
<item name="colorPrimaryVariant">#3F7ABD</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
这是我毕业的一部分
dependencies {
// Extra
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.2.1'
// Compat
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
// TU TI
testImplementation 'org.hamcrest:java-hamcrest:2.0.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
【问题讨论】:
-
你能显示你的themes.xml文件吗?
-
@DrHowdyDoo 我在原帖里加了
-
你用的是什么材料设计版本?
-
我用的是最后一个稳定的 1.2.1,我也试过用 1.3.rc1。我也将我的 graddle 添加到原始帖子中
标签: java android material-design android-theme android-chips