EditText 在 view to bitmap 后,无法显示内容
罪魁祸首: android:inputType=”numberDecimal”,我在将 RecyclerView 变成 Bitmap 的途中,发现 EditText 中的内容有的可以显示,有的不可以显示,最后发现,加了 以上属性 的 EditText 不显示它的内容,去掉之后就可以了。
UriUtils
@SuppressLint("NewApi")
public class UriUtils {
/**
* Get a file path from a Uri. This will get the the path for Storage Access
* Framework Documents, as well as the _data field for the MediaStore and
* other file-based ContentProviders.
*
* @param context The context.
* @param uri The Uri to query.
*/
public static String getPath(final Context context, final Uri uri) {
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
}
// TODO handle non-primary volumes
}
// DownloadsProvider
else if (isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
return getDataColumn(context, contentUri, null, null);
}
// MediaProvider
else if (isMediaDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
final String selection = "_id=?";
final String[] selectionArgs = new String[] {
split[1]
};
return getDataColumn(context, contentUri, selection, selectionArgs);
}
}
// MediaStore (and general)
else if ("content".equalsIgnoreCase(uri.getScheme())) {
return getDataColumn(context, uri, null, null);
}
// File
else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
}
/**
* Get the value of the data column for this Uri. This is useful for
* MediaStore Uris, and other file-based ContentProviders.
*
* @param context The context.
* @param uri The Uri to query.
* @param selection (Optional) Filter used in the query.
* @param selectionArgs (Optional) Selection arguments used in the query.
* @return The value of the _data column, which is typically a file path.
*/
public static String getDataColumn(Context context, Uri uri, String selection,
String[] selectionArgs) {
Cursor cursor = null;
final String column = "_data";
final String[] projection = {
column
};
try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
null);
if (cursor != null && cursor.moveToFirst()) {
final int column_index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(column_index);
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is ExternalStorageProvider.
*/
public static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is DownloadsProvider.
*/
public static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is MediaProvider.
*/
public static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
}
Android 横向 ProgressBar 进度条左右都是 圆角(需要注意的是:使用圆角图片的话,尽管是 .9,圆角在拉伸的状态下还是会有一些变形)
ProgressBar:
<ProgressBar
android:id="@+id/studyProgress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="1dp"
android:minHeight="17dp"
android:progress="80"
android:progressDrawable="@drawable/progress_course_study" />
drawable/progress_course_study:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--3个层的顺序即为显示时的叠加顺序-->
<!--背景色-->
<item android:id="@android:id/background">
<shape>
<corners android:radius="20dip" />
<solid android:color="#f3e8e8" />
</shape>
</item>
<!--二级进度条的颜色-->
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<solid android:color="#88F56100" />
</shape>
</clip>
</item>
<!--一级进度条的颜色,也可以直接替换成图片-->
<item android:id="@android:id/progress">
<scale
android:drawable="@drawable/shape_progress_course_study"
android:scaleWidth="100%" />
</item>
</layer-list>
drawable/shape_progress_course_study:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="20dip" />
<solid android:color="#ff8c94" />
</shape>
Android SDK 7.1.1 版本中 Toast 导致:BadTokenException
具体原因&解决办法:ToastCompat
使用ExoPlayer替换MediaPlayer
mediaPlayer 对视频的支持没有 ExoPlayer 那么广泛,对支持不好的视频会发生断流问题
SeekBar
- width 是 match_parent 的状态下,自定义的滑动块(thumb)会被吃掉一部分,使用属性 “android:thumbOffset=”0dp”“ 即可搞定
WebView
2018/1/8
事实上这么做发现,在性能差一点的手机上依然会出现一闪而过的现象
解决办法:我在 WebView 的上面一层,盖了一层白色的不透明 View,1s 后消失,完美解决
- 动态修改需要 load 的网页的显示,例:去除 id 为 activity-name 的头部 div
webview.loadUrl("JavaScript:(function mFunc(){document.getElementById('activity-name').parentElement.removeChild(document.getElementById('activity-name'));})();");
ps:需要注意的是,头部一闪才会消失,我的做法,先让 webview invisiable,在 visiable,中间有个 1s 的 delayTime