易采站长站为您分析Android开发常用经典代码段,涉及Android开发过程中针对手机、联系人、图片、存储卡等的相关操作技巧,非常简单实用,需要的朋友可以参考下
本文实例总结了Android开发常用经典代码段。,具体如下:
1、图片旋转
Bitmap bitmapOrg = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.moon);
Matrix matrix = new Matrix();
matrix.postRotate(-90);//旋转的角度
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
bitmapOrg.getWidth(), bitmapOrg.getHeight(), matrix, true);
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
2、获取手机号码
//创建电话管理 TelephonyManager tm = (TelephonyManager) //与手机建立连接 activity.getSystemService(Context.TELEPHONY_SERVICE); //获取手机号码 String phoneId = tm.getLine1Number(); //记得在manifest file中添加 <uses-permission android:name="android.permission.READ_PHONE_STATE" /> //程序在模拟器上无法实现,必须连接手机
3.格式化string.xml 中的字符串
// in strings.xml.. <string name="my_text">Thanks for visiting %s. You age is %d!</string> // and in the java code: String.format(getString(R.string.my_text), "oschina", 33);
4、android设置全屏的方法
A.在java代码中设置
/** 全屏设置,隐藏窗口所有装饰 */
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);










