日常开发中碰到了各种开发问题,捡选了一部分分享出来。有些问题非常简单,属于编码规范类,有些属于特定情况下碰到的问题,不是很常见。不太准确的地方,欢迎共同探讨下~
1.requestFeature() must be called before adding contentrequestWindowFeature(Window.FEATURE_NO_TITLE);// 隐藏标题
需要在onCreate之前调用,否则在4.4.2的机型上会报错:
2.小米6.0系统打开浏览器时闪退Calling startActivity() from outside of an Activity context requires the FLAG_NEW_TASK flag.
public static void openBrowser(Context context, String url) {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
也就是要加上面的FLAG_ACTICITY_NEW_TASK(其它手机看到是ok的)
3.设置TextView的颜色值无效 titleTv.setTextColor(colorId);//错误的方式(常见封装类调用)
titleTv.setTextColor(ContextCompat.getColor(context,colorId));//正确的方式
4.国际化引用问题
a.静态/类全局变量需要单独判断;
b.string 中文本空格效果无法体现,给字符串加上双引号
<string name="Chinese"> 中 文 </string>
<string name="Chinese">" 中 文 "</string>
注意:使用Application.getString的方式,在切换语言后,并没有切换这种方式引用的资源内容。可以改为另外的activity里面的getString方法获取
5.魅族7.0的系统在webview中点击后闪退ActivityManagerForce removing ActivityRecord{6dd5804 u0 包名/当前WebviewActivity t8819}: app died, no saved state
不支持onCustumView方法,去掉即可
6.button上的英文默认为大写android:textAllCaps="false"
7.vivo上收到push后打不开指定的页面(根本就没反应)
系统会自动弹出,但是进入设置打开即可。
8.TextView显示不全TextView使用WrapContent,lines=1但是内容显示不全
只能显示在屏幕内的部分,在屏幕外的部分,在属性动画拉出来看的时候就没有。
(这种问题发生在自定义跑马灯控件时)
public static int getTextViewLength(TextView view, String text) {
TextPaint paint = view.getPaint();
int textLength = (int) Layout.getDesiredWidth(text, 0, text.length(), paint);
return textLength;
}
然后给TextView设置宽度。
9. No Activity found to handle Intent { act=android.intent.action.VIEW_DOWNLOADS flg=0x10000000 }三星 SM-C7000(C7) 6.0.1的系统就会出现在这个问题
if(intent.resolve(context.getPackageManager))!=null){
...
}
使用隐式intent进行startActivity时,最好加上该种判断和try catch,因为保不准哪种机型就出问题了
10.设置dialog边角getWindow().setBackgroundDrawableResource(R.drawable.widget_dialog_round_corner);
11.三星机型报错E/rsC (16241): RS CPP error: Blur radius out of 0-25 pixel bound
大意就是TextView的shadowRadius不能大于25,是xml代码中的问题,改小shadowRadius即可。