我们使用CheckBox时希望简单的设置一个有状态的背景,并隐藏其默认样式。可是,当我们调用setButtonDrawable(null)或setButtonDrawable(0)时,却发现完全没有效果。
解决方案:
button.setButtonDrawable(new ColorDrawable(Color.TRANSPARENT));
java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets
由于 StandardCharsets.UTF_8引用的 java.nio.charset.StandardCharsets 包不支持 android SDK 19 以下的版本
解决方案:
使用 Charset.forName("UTF-8") | text.getBytes("UTF-8") 替换 StandardCharsets.UTF_8
java.lang.NullPointerException java.util.concurrent.ConcurrentSkipListMap.put(ConcurrentSkipListMap.java:1616)
ConcurrentSkipListMap支持androidSDK 23及以上版本
解决方案:
使用HashMap代替ConcurrentSkipListMap
java.lang.NoSuchMethodError:android.content.Context.getDrawable
android SDK 22一下版本中使用setBackgroundDrawable(context.getDrawable(R.drawable.***)时出现的这个错误
解决方案:
setBackgroundDrawable(ContextCompat.getDrawable(context,R.drawable.***));
setResult(Activity.RESULT_OK,Intent)失败
AndroidSDK 19以下使用setResult(resultCode,Intent)时resultCode无法传递
解决方案:
1、检查setResult(resultCode,Intent)是否在finish()之前
2、检查activity的启动模式是否为单例模式(singleTask | singleInstance),更改为 standard
使用tint着色无效
tint是Android SDK 21之后引入的属性,在5.0之前无法直接使用tint着色
解决方案
//注意,该方法对通过image.setImageDrawable()设置的图标无效
imageView.setColorFilter(color);
/**
* 重绘Drawable,将drawable颜色着色为color
*/
public static Drawable tint(Drawable drawable, int color) {
final Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
wrappedDrawable.mutate();
DrawableCompat.setTint(wrappedDrawable, color);
return wrappedDrawable;
}