我在用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" />
My code:
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>
结果:
我打开应用程序,然后游戏活动和所有按钮都正确显示。我按下按钮设置滤色器,返回主菜单并重新打开游戏活动,现在所有按钮都是绿色的。
有任何想法吗?