【旧】记录一些蛋疼的bug(一)
写于 2015年 12 月 21 日
-
主题适配时,drawable 错误 ...... Caused by: android.content.res.Resources$NotFoundException: File res/drawable/menu_shape.xml from drawable resource ID #0x7f020179 ...... Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
drawable 中 对 attr color 进行引用导致报错
具体看 https://code.google.com/p/android/issues/detail?id=26251
Android 系统 的 bug,color 无法被引用到drawable中,只能一个主题一个drawable,5.0以上修复此bug
-
相册问题
不同版本下,系统相册的位置是不同的,建议创建一个自己的文件夹,具体操作,通过
Environement.get..
来获取系统环境下的sd卡目录,然后创建文件夹
Intent intent = newIntent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);//系统拍照
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);//画质
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);//保存到uri
Environment.getExternalStorageDirectory();//获取uri时,用这个方法,不然容易不同版本不问题
- XwalkView(14)截图问题
http://stackoverflow.com/questions/29483028/how-can-i-capture-the-whole-view-into-a-bitmap-when-using-crosswalk-to-display-w
http://www.cnblogs.com/ct2011/p/4100132.html
注意:
-
XWalkPreferences.setValue(XWalkPreferences.ANIMATABLE_XWALK_VIEW, true)
需要在load之前就设置,在activity
的onCreate()
设置,onDestroy()
中去除 -
获取
TextureView
:private TextureView findXWalkTextureView(ViewGroup group) { int childCount = group.getChildCount(); for (int i = 0; i < childCount; i++) { View child = group.getChildAt(i); if (child instanceof TextureView) { String parentClassName = child.getParent().getClass().toString(); boolean isRightKindOfParent = (parentClassName.contains("XWalk")); if (isRightKindOfParent) { return (TextureView) child; } } else if (child instanceof ViewGroup) { TextureView textureView = findXWalkTextureView((ViewGroup) child); if (textureView != null) { return textureView; } } } return null; }
-
截图:
public Bitmap captureImage(XWalkView xWalkView) { if (xWalkView != null) { Bitmap bitmap = null; boolean isCrosswalk = false; try { Class.forName("org.xwalk.core.XWalkView"); isCrosswalk = true; } catch (Exception e) { e.printStackTrace(); } if (isCrosswalk) { try { TextureView textureView = findXWalkTextureView(xWalkView); bitmap = textureView.getBitmap(); } catch (Exception e) { e.printStackTrace(); } } else { bitmap = Bitmap.createBitmap(xWalkView.getWidth(), xWalkView.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bitmap); xWalkView.draw(c); } return bitmap; } else { return null; } }
- popwindow 和 menu物理键 第二次无法触发,以及第二次直接弹出并且隐藏问题
主要原因是,popwindow 添加了window从而截取了menu事件,所以activity处无法获取
http://www.bkjia.com/Androidjc/988767.html
Activity 代码:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_MENU:
isMenuShow = true;
showPopupWindow();
break;
}
return super.onKeyDown(keyCode, event);
}
showPopupWindow:
private void showPopupWindow() {
View view = inflater.inflate(R.layout.popupwindow, null);
ll.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
if (!isMenuShow) {
popupWindow.dismiss();
}
isMenuShow = false;
}
return false;
}
});
- Android appcompat-v7 兼容包导致 MENU 按键不能监听到的解决方案
https://twiceyuan.com/2015/05/07/Android-appcompat-v7-兼容包导致-MENU-按键不能监听到的解决方案/
-
bug 5.0 以上 button 中设置 text 英文状态下会变成大写
解决方法:android:textAllCaps="false"
-
Android 6.0(23) 源码中,String类的实现被替换了,具体调用的时候,会调用一个StringFactory来生成一个String,不过一直没有找到入口
public String(char[] data) { throw new UnsupportedOperationException("Use StringFactory instead."); }
除此之外,android 下 String 类实现与 Oracle 的实现完全不一样
-
全球化问题,语言切换
compileSdkVersion 23
版本的时候需要
resources.updateConfiguration(config, dm);
不然没用
http://blog.csdn.net/sodino/article/details/6596709 -
三星的傻逼,拍照会旋转,导致原
activity
重生,从而触发onCreate()
在AndroidManifest.xml
对应的activity
写上 ·android:screenOrientation="landscape"
(landscape = 横向 portrait = 纵向)
android:configChanges="keyboardHidden|orientation"
-
遇到一个傻逼的bug,前几天还可以构建,放完假以后,运行项目突然报错,应该与我用的studio beat 版相关:
报错为:Plugin is too old,please update to a more recent version,or set ANDROID_DAILY_OVERRIDE environment variable to "XXXXX"
点下面的Fix plugin version and sync project
依旧报错,无用。
后来发现是build.gradle 里classpath的问题 我用的是 2.0.0 alpha1 改成1.2.3
或者改成最新的 alpha3,等待下载重新构建就可以了
com.android.tools.build:gradle:1.2.3
建议用1.2.3,alpha3需要更新2.8的gradle,又要更新,有点麻烦 -
"Bitmap too large to be uploaded into a texture"
解决方案,重新设置 bitmap 大小,OpenGL limit 是 2048 * 2048 -
kitkat
之前listview
的addHeaderView()
需要在setAdapter之前调用,
kitkat
之后addHeaderView()
可以在前后调用 -
RecyclerView
23.1.1 版有 bug,解决方案,重写LineaLayoutManager
的onLayoutChildren
@Override public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { try { super.onLayoutChildren(recycler, state); } catch (IndexOutOfBoundsException e) { Log.e("probe", "meet a IOOBE in RecyclerView"); }
}
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder
http://stackoverflow.com/questions/31759171/recyclerview-and-java-lang-indexoutofboundsexception-inconsistency-detected-in
-
Fresco 停止恢复加载
Fresco.getImagePipeline().resume();
Fresco.getImagePipeline().paused();
-
不知道为什么的bug,记录,子布局 marginBottom 没作用,父级布局中 paddingBottom 可以用
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/item_tc_home_root_cv" android:layout_marginBottom="16dp" app:cardBackgroundColor="@color/color_white" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="200dp"/> <RelativeLayout android:paddingBottom="16dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ffffff"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:layout_marginTop="10dp" android:id="@+id/linear_one" android:orientation="vertical"> <com.facebook.drawee.view.SimpleDraweeView app:placeholderImage="@mipmap/icon_head_image" app:roundAsCircle="true" android:layout_width="60dp" android:layout_height="60dp" android:src="@mipmap/icon_head_image" android:id="@+id/avatar_iv" /> </LinearLayout> <LinearLayout android:layout_width="200dp" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:orientation="horizontal" android:layout_marginTop="16dp" android:layout_marginRight="16dp" android:id="@+id/linear_two" android:weightSum="3"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textSize="16sp" android:textColor="#ff467d" android:id="@+id/post_count_tv" android:text="45" android:gravity="center"/> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textSize="16sp" android:textColor="#ff467d" android:id="@+id/fans_count_tv" android:text="2322" android:gravity="center"/> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textSize="16sp" android:textColor="#ff467d" android:id="@+id/follow_count_tv" android:text="172" android:gravity="center"/> </LinearLayout> <LinearLayout android:layout_width="200dp" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_alignParentRight="true" android:layout_below="@+id/linear_two" android:layout_marginTop="16dp" android:layout_marginRight="16dp" android:id="@+id/linear_three" android:weightSum="3" > <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textColor="#999999" android:textSize="12sp" android:text="帖子" android:gravity="center"/> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textColor="#999999" android:textSize="12sp" android:text="粉丝" android:gravity="center"/> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:textColor="#999999" android:textSize="12sp" android:text="关注" android:gravity="center"/> </LinearLayout> <TextView android:layout_marginLeft="48dp" android:layout_below="@+id/linear_one" android:layout_width="wrap_content" android:layout_marginTop="16dp" android:layout_height="wrap_content" android:singleLine="true" android:textSize="18sp" android:gravity="center" android:id="@+id/oldDriver_name_tv" android:textColor="#4c4c4c" android:text="大哥"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/oldDriver_name_tv" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:text="cos 爱好者、我的博客地址:http:www....." android:textColor="#999999" android:textSize="14sp" android:id="@+id/personal_description_tv" android:layout_marginTop="16dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/personal_description_tv" android:layout_marginTop="16dp" android:gravity="center"> <ImageView android:layout_width="114dp" android:layout_height="48dp" android:src="@mipmap/follow" android:id="@+id/follow_iv"/> </LinearLayout> </RelativeLayout>
-
ICCP: Not recognizing known sRGB profile that has been edited
错误,好像是png
是sRGB
导致的错误,解决方案在buildToolsVersion
下面加:aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false
可以取消Android Studio
对图片合法性的检查(参考:http://my.oschina.net/1pei/blog/479162)
- debug.keystore 问题(不同可以跑不同apk,不过大部分apk会有验证,回到导致APP运行失败)
- 隐式调用在5.0后不允许,两种方案:
- 该成显式调用
Intent serviceIntent = new Intent(context,MyService.class);
context.startService(serviceIntent);
- 加上包名
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolveInfoList = pm.queryIntentServices(implicitIntent, 0);
if (resolveInfoList == null || resolveInfoList.size() != 1) {
return null;
}
ResolveInfo serviceInfo = resolveInfoList.get(0);
ComponentName component = new ComponentName(serviceInfo.serviceInfo.packageName, serviceInfo.serviceInfo.name);
Intent explicitIntent = new Intent(implicitIntent);
explicitIntent.setComponent(component);
- service 需要先unbind(如果bind过的话),不然无法stopService
- ExecutorService 的 execute 和 submit 方法,前者会往外部抛出错误,后者不会。参考ExecutorService的坑