Issue with setColorFilter on button background (Android 5)

KracsNZ

New member
Oct 17, 2015
1
0
0
Visit site
Hi guys,

Teaching myself Android JAVA but am struggling with an issue that's affecting only one major version of Android, which appears to be all of 5.

I have an app using SupportFragments with the v4 support library (also tried it with framework fragments using v13 support library). On two of the fragments I have a ScrollView containing a large set of custom buttons. Both of these screen have an issue where the setColorFilter is being ignored when the scroll position is at the very top of the ScrollView. Oddly, if I scroll even 1 pixel the setColorFilter is working. Baffling.

Note, this only affects Android 5. Android 4, and Android 6 work perfectly. Only the various flavors of 5 I've tested with so far have this problem (5.1.1 - Cyanogen S4, and 5.0.2 - Galaxy Tab S2). The Nexus 9 (6.0), Galaxy Tab 2 (4.2.2) and Galaxy Tab 3 (4.4.2) all work fine.

Below is the example of the the scroll being at the top of the scrollview, and then scrolling by just a tiny margin showing the color filter applied.

Screenshot_2015-10-16-16-14-12.jpg
Screenshot_2015-10-16-16-14-32.jpg

The buttons are initially added in the populate method called from the Fragments onCreateView using:

Code:
PasswordButton<Password> btn = (PasswordButton<Password>)inflater.inflate(R.layout.password_button, viewGroup, false);
btn.setObject(password);

The setObject(password) actually sets a password object to the button, and applies the color filter that it inherits from it's password group to the background using the following code (again all from the onCreateView):

Code:
public void setColour() {
		int colour = ((ButtonInterface)this.object).getColour();
		Drawable background = ContextCompat.getDrawable(getContext(), R.drawable.password_button_selector);
		background.setColorFilter(new PorterDuffColorFilter(colour, PorterDuff.Mode.MULTIPLY));
		this.setBackground(background);
	}

The button's style is a made up of a 9patch background (which is where I'm applying the color filter), a small arrow image, and the text.

I've made a workaround by overriding the onDraw completely for Android 5, and all other variants simply calling super(canvas), but it would be nice to not have to do this as if I start skinning the buttons my custom onDraw will need constant updating.

The searching I've done found allot of issues the other way (i.e. 5 working, but 4 not), and the ones I've found that had issues with 5 I'm already using the methods they say got it working.

Any help would be appreciated :)