android常见问题4

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(),能够比较完美的解决一些提交表单页面多次提交问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值