美文网首页
Android 值得记录的几个点

Android 值得记录的几个点

作者: IT一书生 | 来源:发表于2018-03-14 16:06 被阅读5次
  • 通过Drawable的方式改变shap背景颜色
// 以 shap 作为背景,改变 shap 的背景颜色  
TextView test = (TextView) findViewById(R.id.tv_test);  
  
GradientDrawable drawable = (GradientDrawable) test.getBackground();  
drawable.setColor(Color.GREEN);  
drawable.setAlpha(120);  
test.setBackgroundDrawable(drawable);  
  • 设置状态栏的高度
<View  
     android:id="@+id/status_line"  
     android:layout_width="match_parent"  
     android:layout_height="0dp" />  
int statusBarHeight = mContext.getResources().getDimensionPixelSize
                  (mContext.getResources().getIdentifier("status_bar_height", "dimen", "android"));  
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams
                  (ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight);  
mTitleTop.setLayoutParams(params); 
  • RecyclerView 屏蔽滑动
    解决ScrollView嵌套RecyclerView获得焦点问题
LinearLayoutManager mLayoutManager = new LinearLayoutManager(mContext) {  
       @Override  
       public boolean canScrollVertically() {  
           return false;  
      }  
}; 
  • 屏蔽listview的焦点
listview.setFocusable(false);  
  • 获得自定义View宽高
    /** 
     * 获取到布局文件的高度和宽度 
     * 
     * @param child 
     */  
    private void measureView(View child) {  
        ViewGroup.LayoutParams lp = child.getLayoutParams();  
        if (lp == null) {  
            lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);  
        }  
        int childMeasureWidth = ViewGroup.getChildMeasureSpec(0, 0, lp.width);  
        int childMeasureHeight;  
        if (lp.height > 0) {  
            childMeasureHeight = View.MeasureSpec.makeMeasureSpec(lp.height, View.MeasureSpec.EXACTLY);  
        } else {  
            childMeasureHeight = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);  
        }  
        child.measure(childMeasureWidth, childMeasureHeight);  
    }  

应用

设置 view  measureView(自定义view);  
高  childView.getMeasuredHeight()  
宽  childView.getMeasuredWidth() 
  • 反射得到资源
    /**   
     * 反射得到资源id   
     *    
     * @param context   
     * @param key   
     *            传入参数,如"R.drawable.ic_launcher", "R.id.textview"   
     * @return   
     */    
    public static int getResourceId(Context context, String key) {    
        String[] keys = key.split("\\.");    
        Resources res = context.getResources();    
        return res.getIdentifier(keys[2], keys[1], context.getPackageName());    
    }  
  • 判断多次点击
private static long lastClickTime = 0;    
    private static final long DIFF = 800;    
    
    /**   
     * 判断两次点击的间隔,如果小于diff,则认为是多次无效点击   
     *   
     * @return   
     */    
    public boolean isFastDoubleClick() {    
        long time = System.currentTimeMillis();    
        long timeD = time - lastClickTime;    
        lastClickTime = time;    
        if (timeD < DIFF) {    
            return true;    
        }    
        return false;    
    }
  • FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS:
    如果调出的Activtivity只是一个功能片段,并没有实际的意义,也没有必要出现在长按Home键调出最近使用过的程序类表中,那么使用FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
Intent intent = new Intent(this, WaitingFallBackDialog.class); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 
startActivity(intent); 

相关文章

  • Android 值得记录的几个点

    通过Drawable的方式改变shap背景颜色 设置状态栏的高度 RecyclerView 屏蔽滑动解决Scrol...

  • 记录下的几个点

    1不是知道的少,而是坚守的多 2小新带小白出去散步会带上袋子和铲子,这是20多年前的动画片 3不要到处宣扬自己的内...

  • 随便记录几个点

    1,rancher安装 防火墙,selinux关掉,node的docker更新到17.03.2(虽然 官网上说13...

  • Android学习入口记录大全(值得推荐)

    Android学习入口记录大全 重点内容来自我从事android以来收藏以及其他借鉴整理的各种好资源,个人觉得值得...

  • 哈哈

    Android学习入口记录大全 重点内容来自我从事android以来收藏以及其他借鉴整理的各种好资源,个人觉得值得...

  • Android 第三方库

    值得一看 推荐几个开源库 你最不想错过的 2017 早期 25 个 Android 开源库 1.1 Android...

  • Android 按钮按下特效--缩放

    功能虽说简单,但也值得记录!先上刺刀!看招: 话不多说,上菜:布局XML android:background的b...

  • Android内存泄露的几个点

    1.内部类造成的内存泄露。 Activity对象是存在堆内存中的,而内部类静态实例是存放在方法区中,GC机制是回收...

  • 《皮肤的秘密》记录几个点

    这是一本科普书,希望通过这本书知道如何保持皮肤健康。估计姑娘们最感兴趣的部分应该是护肤部分,哈哈,我也不例外。我想...

  • Android系统的启动

    本文用于记录Android系统相关知识点。主要是文字总结~ 一、Android系统架构 Android系统架构分为...

网友评论

      本文标题:Android 值得记录的几个点

      本文链接:https://www.haomeiwen.com/subject/bhhofftx.html