【发布时间】:2014-11-19 11:32:32
【问题描述】:
我正在使用setColorFilter 设置我的按钮之一的颜色过滤器。在 Android 5.0 Lollipop 更新之前,它一直运行良好。现在,即使我关闭活动并重新打开(如果我关闭应用程序并重新打开,它也会重置),颜色过滤器似乎泄漏到我的其他按钮上。
我的 styles.xml (v21):(与旧版本相同,除了这里它的父级是 Material,在它是 Holo 之前)
<style name="Theme.FullScreen" parent="@android:style/Theme.Material.Light.NoActionBar.Fullscreen">
<item name="android:buttonStyle">@style/StandardButton</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
我的 styles.xml(适用于所有版本):
<style name="StandardButton" parent="android:style/Widget.Button">
<item name="android:background">@android:drawable/btn_default</item>
</style>
我的按钮:
<Button
android:id="@+id/mainMenuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="mainMenu"
android:text="@string/button_mainMenu"
android:visibility="gone" />
我的代码:
Button mainMenuButton = (Button) findViewById(R.id.mainMenuButton);
mainMenuButton.getBackground().setColorFilter(new PorterDuffColorFilter(getResources().getColor(R.color.light_green), PorterDuff.Mode.MULTIPLY));
mainMenuButton.setVisibility(View.VISIBLE);
颜色:
<color name="light_green">#5CD65C</color>
结果:
我打开应用程序,然后游戏活动和所有按钮都正确显示。我按下按钮设置颜色过滤器,返回主菜单并重新打开游戏活动,现在所有按钮都是绿色的。
有什么想法吗?
【问题讨论】:
标签: android android-layout android-5.0-lollipop android-styles