1.输入框光标问题
最好在style中配置统一样式的按钮 和输入框
在Edittext中加入以下属性
android:cursorVisible="true"
android:textCursorDrawable="@drawable/test_cursor"
对应的drawable文件
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="1dp" />
<span style="font-family: Arial, Helvetica, sans-serif;"><!-- 光标宽度可以自己定义 --></span>
<solid android:color="#000000" /><!-- 光标颜色可以自己定义 -->
</shape>
2.TabLayout混淆问题报错
TabLayout ‘mTabStrip’ 混淆问题报错 field mTabStrip in class Landroid/support/design/widget/TabLayout
-keep class android.support.design.widget.TabLayout{*;}
3.BitmapFactory.decodeFile()返回为null 遇到后的处理
final BitmapFactory.Options options = new BitmapFactory.Options();
// 该值设为true那么将不返回实际的bitmap不给其分配内存空间而里面只包括一些解码边界信息即图片大小信息
options.inJustDecodeBounds = true;// inJustDecodeBounds设置为true,可以不把图片读到内存中,但依然可以计算出图片的大小
BitmapFactory.decodeFile(filePath, options);
// Calculate inSampleSize 根据高宽度和屏幕高宽度计算压缩程度
options.inSampleSize = calculateInSampleSize(options, w, h);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;// 重新读入图片,注意这次要把options.inJustDecodeBounds
// 设为 false
Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);// BitmapFactory.decodeFile()按指定大小取得图片缩略图
4.混淆引发的错误
用到网络上获取地址api24+的路径方法
/**
* 鑾峰彇FileProvider path
* author zx
* version 1.0
* since 2018/5/4 .
*/
public static String getFPUriToPath(Context context, Uri uri) {
try {
List<PackageInfo> packs = context.getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS);
if (packs != null) {
String fileProviderClassName = FileProvider.class.getName();
for (PackageInfo pack : packs) {
ProviderInfo[] providers = pack.providers;
if (providers != null) {
for (ProviderInfo provider : providers) {
if (uri.getAuthority().equals(provider.authority)) {
if (provider.name.equalsIgnoreCase(fileProviderClassName)) {
Class<FileProvider> fileProviderClass = FileProvider.class;
try {
Method getPathStrategy = fileProviderClass.getDeclaredMethod("getPathStrategy", Context.class, String.class);
getPathStrategy.setAccessible(true);
Object invoke = getPathStrategy.invoke(null, context, uri.getAuthority());
if (invoke != null) {
String PathStrategyStringClass = FileProvider.class.getName() + "$PathStrategy";
Class<?> PathStrategy = Class.forName(PathStrategyStringClass);
Method getFileForUri = PathStrategy.getDeclaredMethod("getFileForUri", Uri.class);
getFileForUri.setAccessible(true);
Object invoke1 = getFileForUri.invoke(invoke, uri);
if (invoke1 instanceof File) {
String filePath = ((File) invoke1).getAbsolutePath();
return filePath;
}
}
} catch (NoSuchMethodException | InvocationTargetException | ClassNotFoundException | IllegalAccessException e) {
e.printStackTrace();
}
break;
}
break;
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
时出现混淆了包含反射的方法导致拍照获取不到图片的uri,这个问题找了很久,在混淆中加了很多过滤都没用~、~
后面用方法
/**
* 根据Uri返回文件绝对路径
* 兼容了file:///开头的 和 content://开头的情况
*/
public static String getRealFilePathFromUri(final Context context, final Uri uri) {
if (null == uri) { return null; }
final String scheme = uri.getScheme();
String data = null;
if (scheme == null) {
data = uri.getPath();
} else if (ContentResolver.SCHEME_FILE.equalsIgnoreCase(scheme)) {
data = uri.getPath();
} else if (ContentResolver.SCHEME_CONTENT.equalsIgnoreCase(scheme)) {
Cursor cursor = context.getContentResolver()
.query(uri,
new String[]{MediaStore.Images.ImageColumns.DATA},
null,
null,
null);
if (null != cursor) {
if (cursor.moveToFirst()) {
int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
if (index > -1) {
data = cursor.getString(index);
}
}
cursor.close();
}
}
return data;
}
替代就好了
5.提交按钮的重复点击处理方案
可以通过设置按钮的setEanble(false)事件和按钮提交的showLoading()动画配合使用,等到接口请求完成或者失败再设置setEnable(true)和关闭动画dimissLoading(),能够比较完美的解决一些提交表单页面多次提交问题