android 日常(二十)

  • 获取状态栏高度
private static int getStatusBarHeight() {  
        Class<?> c = null;  
        Object obj = null;  
        Field field = null;  
        int x = 0, sbar = 0;  
        try {  
            c = Class.forName("com.android.internal.R$dimen");  
            obj = c.newInstance();  
            field = c.getField("status_bar_height");  
            x = Integer.parseInt(field.get(obj).toString());  
            sbar = mContext.getResources().getDimensionPixelSize(x);  
        } catch (Exception e1) {  
            e1.printStackTrace();  
        }  
        return sbar;  
    }
  • 让悬浮窗覆盖状态栏
public class ToastUtils {
    private static Toast toast;
    private static Context mContext;
    public static void show(Context context,String text,int duration){
        mContext = context;
        if(null == toast){
            toast = Toast.makeText(mContext, text, duration);
        }
        else{
            toast.setText(text);
            toast.setDuration(duration);
        }
        toast.show();
    }
    
    public static void show(Context context,int id,int duration){
        mContext = context;
        if(null == toast){
            toast = Toast.makeText(mContext, id, duration);
        }
        else{
            toast.setText(id);
            toast.setDuration(duration);
        }
        toast.show();
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,552评论 25 708
  • 前言:toast再常见不过,但是一个小小的toast居然内有乾坤,呵(w)呵(t)呵(f) 源码如下: publi...
    super超_9754阅读 1,362评论 0 0
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,554评论 0 17
  • 本人初学Android,最近做了一个实现安卓简单音乐播放功能的播放器,收获不少,于是便记录下来自己的思路与知识总结...
    落日柳风阅读 19,233评论 2 41
  • 月亮之下是炊烟 炊烟之下是我家 家中只有我一个人 孤孤单单过生活 灶台之外是院子 院子之外是土地 地中只有我一个人...
    山楂树123阅读 627评论 2 6