This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Resources resources = getResources();//获得res资源对象 | |
Configuration config = resources.getConfiguration();//获得设置对象 | |
DisplayMetrics dm = resources .getDisplayMetrics();//获得屏幕参数:主要是分辨率,像素等。 | |
config.locale = Locale.SIMPLIFIED_CHINESE; //简体中文 | |
resources.updateConfiguration(config, dm); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 将科学计数法转换为常规计数法 | |
*/ | |
public static String ConScience2NumValue(String str) | |
{ | |
int len = Integer.parseInt(str.substring(getNum(str),getNum(str)+1)); | |
String bit = "1"; | |
for(int i = 0 ; i<len;i++) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 金额格式化 | |
* @param s 金额 | |
* @param len 小数位数 | |
* @return 格式后的金额 | |
*/ | |
public static String FormatCurrency(String s, int len) { | |
if (s == null || s.length() < 1) { | |
return "0.00"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* /** | |
* 根据手机的分辨率从 dp 的单位 转成为 px(像素) | |
*/ | |
public static int dip2px(Context context, int dpValue) { | |
final float scale = context.getResources().getDisplayMetrics().density; | |
return (int) (dpValue * scale + 0.5f); | |
} | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 获取屏幕大小 | |
* @param context | |
* @return | |
*/ | |
public static int[] getScreenSize(Context context) { | |
DisplayMetrics dm = new DisplayMetrics(); | |
//获取屏幕信息 | |
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm); | |
int screenWidth = dm.widthPixels; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 根据value寻找key | |
* @param map | |
* @param value | |
* @return | |
*/ | |
public static String getMapKeyByValue(HashMap<String, String> map, Object value) { | |
Set<String> kset = map.keySet(); | |
for(String ks : kset){ | |
if(value.equals(map.get(ks))) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getCurVersionName(Context context) { | |
String versionName = null; | |
try { | |
PackageInfo pInfo = context.getPackageManager().getPackageInfo( | |
context.getPackageName(), 0); | |
versionName = pInfo.versionName; | |
} catch (NameNotFoundException e) { | |
versionName = "没有版本号"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Object reflect2(Object obj) { | |
if (obj == null) | |
return null; | |
Field[] fields = obj.getClass().getDeclaredFields(); | |
for (int j = 0; j < fields.length; j++) { | |
fields[j].setAccessible(true); | |
// 字段名 | |
System.out.print(fields[j].getName() + ","); | |
// 字段值 | |
if (fields[j].getType().getName().equals( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer); | |
drawerToggle = setupDrawerToggle(); | |
mDrawerLayout.setDrawerListener(drawerToggle); | |
private ActionBarDrawerToggle setupDrawerToggle() { | |
return new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, | |
R.string.app_name, R.string.app_name); | |
} | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 判断是否是 Tablet | |
* | |
* @param activity Activity | |
* @return true, if is tablet device | |
*/ | |
public static boolean isTablet(Activity activity) { | |
DisplayMetrics dm = new DisplayMetrics(); | |
activity.getWindowManager().getDefaultDisplay().getMetrics(dm); | |
double diagonalPixels = Math.sqrt(Math.pow(dm.widthPixels, 2) + Math.pow(dm.heightPixels, 2)); |
OlderNewer