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);
  • 相关阅读:
    oracle—数据泵及常用参数
    NTP服务及时间同步
    kudu安装
    ogg12c 配置
    ogg12-ERROR OGG-01031 file D:OGGdirdated000000 is not in any allowed output directories
    ogg12c_静默安装
    git的基本使用
    redis数据库
    linux之网络
    flask框架基础
  • 原文地址:https://www.cnblogs.com/Lee1992/p/2981349.html
Copyright © 2011-2022 走看看