1、白色卡片背景.9.png
http://pan.baidu.com/s/1bo1bNdH
2、获取运行内存
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
3、获取Bitmap内存大小
public int getBitmapSize(Bitmap bitmap) {
if (Build.VERSION.SDK_INT >= 12) {// API
return bitmap.getByteCount();
}
return bitmap.getRowBytes() * bitmap.getHeight(); // earlier version
}
4、调转activity
private void startActivity(Class clazz) { Intent intent = new Intent(); intent.setClass(this, clazz); startActivity(intent); }
5、findViewById,减去强转步骤
public class V { public static <T> T findViewById(Activity activity, int id) { return (T) activity.findViewById(id); } public static <T> T findViewById(View view, int id) { return (T) view.findViewById(id); } }
//rv_discovery = (LoadRefreshRecyclerView) view.findViewById(R.id.rv_discovery);
rv_discovery= V.findViewById(view,R.id.rv_discovery);
6、将本地图片装换成bitmap对象
Bitmap myBitmap =BitmapFactory.decodeResource(getResources(), R.mipmap.head_photo);
7、调用系统API打开图库
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, REQUEST_IMAGE);
8、在Activity的onActivityResult方法中获取用户选中的图片
if (requestCode == REQUEST_IMAGE) {
if (data != null) Uri uri = data.getData();
ContentResolver cr = getContentResolver();
//显得到bitmap图片
Bitmap mBitmap = MediaStore.Images.Media.getBitmap(cr, uri);
}
9、字体颜色选择器
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true" android:color="@color/colorBlack"></item> <item android:state_pressed="false" android:color="@color/colorWhite"></item> </selector>
android:textColor="@drawable/textselector1"
10、按钮图片选择器
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/btn_blue_shape" android:state_pressed="false" /> <item android:drawable="@drawable/btn_blue_shape_press" android:state_pressed="true" /> </selector>
btn_blue_shape.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:bottomLeftRadius="20dp" android:bottomRightRadius="20dp" android:topLeftRadius="20dp" android:topRightRadius="20dp"></corners> <padding android:bottom="10dp" android:top="10dp"></padding> <solid android:color="@color/colorPrimaryDark"></solid> </shape>
btn_blue_shape_press.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:bottomLeftRadius="20dp" android:bottomRightRadius="20dp" android:topLeftRadius="20dp" android:topRightRadius="20dp"></corners> <padding android:bottom="10dp" android:top="10dp"></padding> <solid android:color="@color/colorPrimaryDark2"></solid> </shape>
11、状态栏变色
http://pan.baidu.com/s/1mhO0q4C
setContentView(R.layout.activity_login); StatusBarUtils.setColor(this, getResources().getColor(R.color.colorloginbg), 1);
12、文本编辑器
http://pan.baidu.com/s/1gf3lUgz
https://github.com/xmuSistone/android-animate-RichEditor
http://pan.baidu.com/s/1c2ENvTe
http://blog.csdn.net/qq137722697/article/details/52705610
13、隐藏小键盘
public void hideKeyBoard() { InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(lastFocusEdit.getWindowToken(), 0); }
14、getHeight()和getMeasuredHeight()的区别
15、MD5加密
public static String stringToMD5(String intput) {
char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};try {
byte[] btInput = intput.getBytes();
MessageDigest mdInst = MessageDigest.getInstance("MD5");
mdInst.update(btInput);
byte[] md = mdInst.digest();
int j = md.length;
char[] str = new char[j * 2];
int k = 0;for(int i = 0; i < j; ++i) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 15];
str[k++] = hexDigits[byte0 & 15];
}return new String(str);
} catch (Exception var10) {
var10.printStackTrace();
return null;
}
}