Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在控件属性面板中设置字体字体?_Java_Android_Android Studio_Typeface - Fatal编程技术网

Java 如何在控件属性面板中设置字体字体?

Java 如何在控件属性面板中设置字体字体?,java,android,android-studio,typeface,Java,Android,Android Studio,Typeface,我可以用java脚本设置字体,但这是一种不用在小部件属性面板或设计文本模式或其他模式中编程而设置自定义字体的方法吗?您的问题已经在这里得到了回答 这是一个例子 public Bitmap buildUpdate(String time) { Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444); Canvas myCanvas = new Canvas(myBitmap); Paint paint = n

我可以用java脚本设置字体,但这是一种不用在小部件属性面板或设计文本模式或其他模式中编程而设置自定义字体的方法吗?

您的问题已经在这里得到了回答

这是一个例子

public Bitmap buildUpdate(String time) 
{
Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444);
Canvas myCanvas = new Canvas(myBitmap);
Paint paint = new Paint();
Typeface clock = Typeface.createFromAsset(this.getAssets(),"Clockopia.ttf");
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setTypeface(clock);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(65);
paint.setTextAlign(Align.CENTER);
myCanvas.drawText(time, 80, 60, paint);
return myBitmap;
}
这就是字体到图像的部分,下面是如何使用它:

String time = (String) DateFormat.format(mTimeFormat, mCalendar);
RemoteViews views = new RemoteViews(getPackageName(), R.layout.main);
views.setImageViewBitmap(R.id.TimeView, buildUpdate(time));

您可以根据需要调整它

您只能在
android:typeface
属性中支持的选项之间切换。