Android 一些功能代码
发布时间:2020-12-14 23:25:58 所属栏目:Java 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 全屏 requestWindowFeature(Window.FEATURE_NO_TITLE); // 无标题栏需要在setContentView之前getWindow().setFlags(WindowManager.LayoutParams.FLAG_
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考
全屏
requestWindowFeature(Window.FEATURE_NO_TITLE); // 无标题栏需要在setContentView之前 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 也可以在manifest中:
<Activity android:theme="@android:style/Theme.NoTitleBar.Fullscreen".. /> 横屏 >setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);安装apk private void install(File file) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); // intent.setData(Uri.fromFile(file)); // intent.setType("application/vnd.android.package-archive"); //mime的数据类型 plain/text image/jpeg intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");//该mime 表示 .apk 文件类型 startActivity(intent); }精确获取屏幕尺寸(例如:3.5、4.0、5.0寸屏幕)? public static double getScreenPhysicalSize(Activity ctx) { DisplayMetrics dm = new DisplayMetrics(); ctx.getWindowManager().getDefaultDisplay().getMetrics(dm); //对角线像素长 double diagonalPixels = Math.sqrt(Math.pow(dm.widthPixels,2) + Math.pow(dm.heightPixels,2)); return diagonalPixels / (160 * dm.density); //160像素,density=1 } 启动Apk的默认Activity public static void startApkActivity(final Context ctx,String packageName) { PackageManager pm = ctx.getPackageManager(); PackageInfo pi; try { <span style="white-space:pre"> </span>pi = pm.getPackageInfo(packageName,0); Intent intent = new Intent(Intent.ACTION_MAIN,null); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setPackage(pi.packageName); List<ResolveInfo> apps = pm.queryIntentActivities(intent,0); ResolveInfo ri = apps.iterator().next(); if (ri != null) { String className = ri.activityInfo.name; intent.setComponent(new ComponentName(packageName,className)); ctx.startActivity(intent); } } catch (NameNotFoundException e) { Log.e("startActivity",e.getMessage()); } } public static int dip2px(Context context,float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } public static int px2dip(Context context,float pxValue) { <span style="white-space:pre"> </span>final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); }重启应用程序 Intent i = getBaseContext().getPackageManager()// .getLaunchIntentForPackage(getBaseContext().getPackageName()); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); public static float GetTextWidth(String text,float size) { TextPaint fontPaint = new TextPaint(); fontPaint.setTextSize(size); return fontPaint.measureText(text); }? 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |