EditText ed = new EditText(this);        Editable eb = ed.getEditableText();        //获取光标位置        int position = ed.getSelectionStart();        //指定位置插入字符        eb.insert(position, "XXX");        //插入图片        //定义图片所占字节数(“Tag”的长度)        SpannableString ss = new SpannableString("Tag");        //定义插入图片        Drawable drawable = getResources().getDrawable(R.drawable.icon);        ss.setSpan(new ImageSpan(drawable,ImageSpan.ALIGN_BASELINE), 0, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);        drawable.setBounds(2, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());        //插入图片        eb.insert(position, ss);        //设置可输入最大字节数        ed.setFilters(new InputFilter[]{new InputFilter.LengthFilter(10)});        //拉起lancher桌面        Intent i = new Intent(Inten.ACTION_MAIN);       i.addCategory(Inten.CATEGORT_HOME);       startActivity(i);       //去掉List拖动时的阴影        list.setCacheColorHint(0);                   // 通过资源名称获取资源id         1.Field f= (Field)R.drawable.class.getDeclaredField("Name");        int id=f.getInt(R.drawable.class);     2.int id = getResources().getIdentifier(getPackageName()+":drawable/Name", null,null);       // timer TimerTask用法        mTimer = new Timer();        mTimerTask = new TimerTask() {@Overridepublic void run() {mProgress.setProgress(mMediaPlayer.getCurrentPosition());mHandler.sendEmptyMessage(0);}};mTimer.schedule(mTimerTask, 0, 1000);        // 在a.apk启动b.apk的实现         //1.a.apk实现Intent mIntent = new Intent("package.MainActivity"); startActivity(mIntent);finish();         // b.apk在mainfest中配置            <intent-filter>                <action android:name="package.MainActivity" />                <category android:name="android.intent.category.DEFAULT" />            </intent-filter>//Android 获取存储卡路径和空间使用情况       /** 获取存储卡路径 */ File sdcardDir=Environment.getExternalStorageDirectory(); /** StatFs 看文件系统空间使用情况 */ StatFs statFs=new StatFs(sdcardDir.getPath()); /** Block 的 size*/ Long blockSize=statFs.getBlockSize(); /** 总 Block 数量 */ Long totalBlocks=statFs.getBlockCount(); /** 已使用的 Block 数量 */ Long availableBlocks=statFs.getAvailableBlocks(); //Android 为Activity屏幕的标题添加图标Window win = getWindow();  win.requestFeature(Window.FEATURE_LEFT_ICON);  setContentView(R.layout.mylayout);  win.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon);//图片缩放1.ThumbnailUtils.extractThumbnail(bitmap,200,100)2.  //使用Bitmap加Matrix来缩放        public static Drawable resizeImage(Bitmap bitmap, int w, int h)        {            Bitmap BitmapOrg = bitmap;             int width = BitmapOrg.getWidth();             int height = BitmapOrg.getHeight();             int newWidth = w;             int newHeight = h;                float scaleWidth = ((float) newWidth) / width;             float scaleHeight = ((float) newHeight) / height;                Matrix matrix = new Matrix();             matrix.postScale(scaleWidth, scaleHeight);             // if you want to rotate the Bitmap               // matrix.postRotate(45);               Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width,                             height, matrix, true);             return new BitmapDrawable(resizedBitmap);         }  3. //使用BitmapFactory.Options的inSampleSize参数来缩放        public static Drawable resizeImage2(String path,               int width,int height)        {           BitmapFactory.Options options = new BitmapFactory.Options();           options.inJustDecodeBounds = true;//不加载bitmap到内存中            BitmapFactory.decodeFile(path,options);            int outWidth = options.outWidth;           int outHeight = options.outHeight;           options.inDither = false;           options.inPreferredConfig = Bitmap.Config.ARGB_8888;           options.inSampleSize = 1;                      if (outWidth != 0 && outHeight != 0 && width != 0 && height != 0)            {               int sampleSize=(outWidth/width+outHeight/height)/2;               Log.d(tag, "sampleSize = " + sampleSize);               options.inSampleSize = sampleSize;           }                 options.inJustDecodeBounds = false;           return new BitmapDrawable(BitmapFactory.decodeFile(path, options));            }  

更多相关文章

  1. Android(安卓)基于4G模块 GPS定位
  2. 获取Android应用程序的签名
  3. android VideoView的使用例程
  4. Android(安卓)Http 异步请求
  5. Android中Bitmap、Drawable、byte[]转换
  6. 箭头函数的基础使用
  7. NPM 和webpack 的基础使用
  8. Python list sort方法的具体使用
  9. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程

随机推荐

  1. Android(安卓)控件布局常用属性
  2. android 电容屏(二):驱动调试之基本概念篇
  3. android修改底层键值
  4. 修改android 系统设置 android 版本
  5. 牛人博客收集
  6. Android实现图片缩放与旋转
  7. mainfest文件中android属性
  8. Android之Handler用法总结
  9. Android防止快速重复点击
  10. Android的AlertDialog详解