android.widget.TextView.buildDrawingCache()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中android.widget.TextView.buildDrawingCache()方法的一些代码示例,展示了TextView.buildDrawingCache()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.buildDrawingCache()方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:buildDrawingCache

TextView.buildDrawingCache介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

public Drawable createFromView(int positionNumber)
{
  LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
  View view = inflater.inflate(R.drawable.pin_icon, null, false);
  TextView tv = (TextView) view.findViewById(R.id.pin_background);
  tv.setText("     "+ (positionNumber+1) );   // +1 since position is starting from 0
  tv.setDrawingCacheEnabled(true);
  tv.layout(0, 0, 50, 50);
  tv.buildDrawingCache();
  Bitmap b = Bitmap.createBitmap(tv.getDrawingCache());
  tv.setDrawingCacheEnabled(false);
  Drawable d = new BitmapDrawable(b);
  return d;
}

代码示例来源:origin: stackoverflow.com

tv.buildDrawingCache();

代码示例来源:origin: stackoverflow.com

public void onClick(View v) {
  tv1.buildDrawingCache();
  iv.setImageBitmap(tv1.getDrawingCache());
  outputc.setText((inputc.getText()));

代码示例来源:origin: stackoverflow.com

EditText editText = (EditText) findViewById(R.id.editText);
TextView textView = new TextView(this.getApplicationContext());

textView.setTypeface(editText.getTypeface());
textView.setText(editText.getText());
textView.measure(
  View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED),
  View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
textView.setDrawingCacheEnabled(true);
textView.buildDrawingCache();

Bitmap b = textView.getDrawingCache().copy(Bitmap.Config.ARGB_8888, false);
textView.destroyDrawingCache();

try{
  String path = Environment.getExternalStorageDirectory().toString() + "/picture.png";
  OutputStream outputStream = new FileOutputStream(new File(path));
  b.compress(Bitmap.CompressFormat.PNG, 0, outputStream);
  outputStream.flush();
  outputStream.close();
} catch (Exception e) {
  e.printStackTrace();
}

代码示例来源:origin: easemob/kefu-android-demo

private Bitmap creatCodeBitmap(String contents, int width, int height, Context context) {
  TextView tv = new TextView(context);
  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
      LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  tv.setLayoutParams(layoutParams);
  tv.setText(contents);
  tv.setHeight(height);
  tv.setGravity(Gravity.CENTER_HORIZONTAL);
  tv.setWidth(width);
  tv.setDrawingCacheEnabled(true);
  tv.setTextColor(Color.BLACK);
  tv.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
      View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
  tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());
  tv.buildDrawingCache();
  Bitmap bitmapCode = tv.getDrawingCache();
  return bitmapCode;
}

相关文章

微信公众号

最新文章

更多

TextView类方法