Android常用的Uiutl
来源:互联网 发布:淘宝买电脑主机 编辑:程序博客网 时间:2024/06/15 10:58
public class UIUtils { public static Context getContext() { return Application.getContext(); } public static Handler getHandler() { return Application.getHandler(); } public static int getMainThreadId() { return Application.getMainThreadId(); } // /////////////////加载资源文件 /////////////////////////// // 获取字符串 public static String getString(int id) { return getContext().getResources().getString(id); } // 获取字符串数组 public static String[] getStringArray(int id) { return getContext().getResources().getStringArray(id); } // 获取图片 public static Drawable getDrawable(int id) { return getContext().getResources().getDrawable(id); } // 获取颜色 public static int getColor(int id) { return getContext().getResources().getColor(id); } //根据id获取颜色的状态选择器 public static ColorStateList getColorStateList(int id) { return getContext().getResources().getColorStateList(id); } // 获取尺寸 public static int getDimen(int id) { return getContext().getResources().getDimensionPixelSize(id);// 返回具体像素值 } // /////////////////dip和px转换////////////////////////// public static int dip2px(float dip) { float density = getContext().getResources().getDisplayMetrics().density; return (int) (dip * density + 0.5f); } public static float px2dip(int px) { float density = getContext().getResources().getDisplayMetrics().density; return px / density; } // /////////////////加载布局文件////////////////////////// public static View inflate(int id) { return View.inflate(getContext(), id, null); } // /////////////////判断是否运行在主线程////////////////////////// public static boolean isRunOnUIThread() { // 获取当前线程id, 如果当前线程id和主线程id相同, 那么当前就是主线程 int myTid = android.os.Process.myTid(); if (myTid == getMainThreadId()) { return true; } return false; } // 运行在主线程 public static void runOnUIThread(Runnable r) { if (isRunOnUIThread()) { // 已经是主线程, 直接运行 r.run(); } else { // 如果是子线程, 借助handler让其运行在主线程 getHandler().post(r); } } }
0 0
- Android常用的Uiutl
- 常用的android
- android 常用的布局
- 常用的 Android API
- android 的常用控件
- Android 的常用方法
- Android的常用传感器
- 常用的android指令
- android 常用的
- Android常用的包
- 常用的Android对话框
- Android 常用的功能
- Android常用的命令
- 常用的android对话框
- android常用的开源库
- 【Android】 常用的Intent
- android常用的命令
- Android 常用的开源库
- SQL结构化查询语言快速入门
- 【每天学一点】C++基础03
- wxPython控件大全
- C++中#if,#ifdef,ifndef
- 关于SpringMVC入门配置
- Android常用的Uiutl
- Ubuntu 14.04安装Matlab2012a过程
- mysql服务重启和关闭
- SpringMVC的实质揭秘图(八)
- 使用百度地图出现java.lang.UnsatisfiedLinkError错误
- jsp与JavaBean
- HOG:用于人体检测的梯度方向直方图 Histograms of Oriented Gradients for Human Detection
- Linux中程序的栈帧分析以及修改函数地址
- RabbitMQ安装与使用