Skip to content

Instantly share code, notes, and snippets.

@S64
Created November 6, 2015 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save S64/d529864fcaef5bf56115 to your computer and use it in GitHub Desktop.
Save S64/d529864fcaef5bf56115 to your computer and use it in GitHub Desktop.
AppCompat v7 disabledAlpha bug
import android.os.Build;
import android.util.TypedValue;
import android.view.View;
/**
* Created by S64 on 15/11/06.
*/
public class Hoge {
public static void setEnabledCompat(View view, boolean enabled) {
{
view.setEnabled(enabled);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
float newAlpha;
if (!enabled) {
TypedValue typedValue = new TypedValue();
view.getContext().getTheme().resolveAttribute(android.R.attr.disabledAlpha, typedValue, true);
newAlpha = typedValue.getFloat();
} else {
newAlpha = 1;
}
view.setAlpha(newAlpha);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment