我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>
Run Code Online (Sandbox Code Playgroud)
我的styles.xml(适用于所有版本):
<style name="StandardButton" parent="android:style/Widget.Button">
<item name="android:background">@android:drawable/btn_default</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我的按钮:
<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" />
Run Code Online (Sandbox Code Playgroud)
我的代码:
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);
Run Code Online (Sandbox Code Playgroud)
颜色:
<color name="light_green">#5CD65C</color>
Run Code Online (Sandbox Code Playgroud)
结果:
我打开应用程序,然后游戏活动和所有按钮都正确显示.我按下按钮设置滤色器,返回主菜单并重新打开游戏活动,现在所有按钮都是绿色.
有任何想法吗?