zoukankan      html  css  js  c++  java
  • android开发常用方法

    1、  //获取屏幕上每一毫米对应的像素数,此方法有时不太准确,需要手机的标准DPI值
            private int getPxOfMM(Context context){
                
                //每1一英寸 == 25.4mm
                float MMCount = 25.4f;
                
                DisplayMetrics dm = context.getResources().getDisplayMetrics();
    //            
                //取对角线上的像素数
                double DiaonalPixels = Math.sqrt(Math.pow(dm.widthPixels, 2)+ Math.pow(dm.heightPixels, 2));
                
                //取对角线的长度(mm)
                double diagonalLength = DiaonalPixels / dm.densityDpi * MMCount;
                
                //得到每一个毫米所对应的像素数
                int result = (int) Math.ceil(DiaonalPixels/diagonalLength);
                
                return result;
            }
    2获取android分辨率
         DisplayMetrics dm = new DisplayMetrics();   
         WindowManager wm = (WindowManager) this.mContext.getSystemService(Context.WINDOW_SERVICE);
         wm.getDefaultDisplay().getMetrics(dm); 
    
     
    
    3、在AndroidMainfest.xml中选择哪个activity,设置windowSoftInputMode属性为adjustUnspecified|stateHidden 
    例如:
    <activity android:name=".Main"                  
     android:label="@string/app_name"  
     android:windowSoftInputMode="adjustUnspecified|stateHidden"                  
     android:configChanges="orientation|keyboardHidden">             
        <intent-filter>                 
            <action android:name="android.intent.action.MAIN" />                 
            <category android:name="android.intent.category.LAUNCHER" />             
        </intent-filter>         
    </activity> 
    
     

     4、3、设置AlertDialog 点击按钮不消失

    try { 
                        Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");  
                        field.setAccessible(true);
                        field.set(dialog, true); //true 为点击之后消失 ,false 为点击之后不消失   
                    } catch (SecurityException e) {  
                        e.printStackTrace();  
                    } catch (NoSuchFieldException e) {  
                        e.printStackTrace();  
                    } catch (IllegalArgumentException e) {  
                        e.printStackTrace();  
                    } catch (IllegalAccessException e) {  
                        e.printStackTrace();  
                    }
    5、控制输入法隐藏的代码
     ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
                                    .hideSoftInputFromWindow(getActivity()
                                                    .getCurrentFocus().getWindowToken(),
                                                    InputMethodManager.HIDE_NOT_ALWAYS);
  • 相关阅读:
    Jmeter 批量执行脚本之-----------Ant
    Linux之vi编辑器的使用
    Linux命令之-ps & kill
    Linux命令详解一:基础命令新建、删除、拷贝~~~
    Linux(Ubuntu)下安装jdk
    Lr-代理录制
    开通博客第一天
    找出列表中重复的元素及个数
    写一个密码校验程序,密码格式为含有大写、小写字母、数字,长度为8位
    创建数据,分页显示,输入要查看的页码,显示指定数据,每页显示10条数据
  • 原文地址:https://www.cnblogs.com/Lee1992/p/2981349.html
Copyright © 2011-2022 走看看