gpt4 book ai didi

android - appcompat v22.1 小部件着色不显示 pre 5.0

转载 作者:搜寻专家 更新时间:2023-11-01 08:43:46 25 4
gpt4 key购买 nike

我正在使用 AppCompat lib v22.1 为多个 android 版本提供一些 Material 设计。如果我使用新的小部件着色功能,即使使用 AppCompat,它也不会出现在 Kitkat 中。

在布局中:

<Button
android:id="@+id/mybtn"
android:text="Test"
android:theme="@style/MyTheme.BlueButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

在主题 xml 中:

<style name="MyTheme.BlueButton">
<item name="colorButtonNormal">@color/blue</item>
</style>

这是我做错了什么还是 AppCompat 中的错误?

最佳答案

通过使用以下设置,我能够在 Kitkat 和 Lollipop 上获得预期的结果:

build.gradle(部分)

dependencies {
compile 'com.android.support:appcompat-v7:22.1.1'
}

值/styles.xml

<resources>

<style name="Theme.AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>

<style name="ThemeOverlay.AppTheme.Blue" parent="ThemeOverlay.AppCompat.Dark">
<!-- ThemeOverlay themes define only some attributes, those which make
backgrounds dark and highlights and texts light for ThemeOverlay.AppCompat.Dark
or the other way around for .Light. The rest is taken from the activity theme.
You only customize what you need - here the button color. -->
<item name="colorButtonNormal">@color/blue_500</item>
</style>

<style name="ThemeOverlay.AppTheme.Yellow" parent="ThemeOverlay.AppCompat.Light">
<!-- This worked correctly even with parent="Theme.AppTheme". -->
<item name="colorButtonNormal">@color/yellow_500</item>
</style>

</resources>

layout/activity_main.xml(部分)

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:theme="@style/ThemeOverlay.AppTheme.Blue"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:theme="@style/ThemeOverlay.AppTheme.Yellow"/>

编辑:(哦,是的,我忘了)MainActivity.java

public class MainActivity extends AppCompatActivity { ... }

结果

Kitkat Lollipop

关于android - appcompat v22.1 小部件着色不显示 pre 5.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30383209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com