<legend id='WwbJp'><style id='WwbJp'><dir id='WwbJp'><q id='WwbJp'></q></dir></style></legend>
  • <small id='WwbJp'></small><noframes id='WwbJp'>

  • <tfoot id='WwbJp'></tfoot>
    <i id='WwbJp'><tr id='WwbJp'><dt id='WwbJp'><q id='WwbJp'><span id='WwbJp'><b id='WwbJp'><form id='WwbJp'><ins id='WwbJp'></ins><ul id='WwbJp'></ul><sub id='WwbJp'></sub></form><legend id='WwbJp'></legend><bdo id='WwbJp'><pre id='WwbJp'><center id='WwbJp'></center></pre></bdo></b><th id='WwbJp'></th></span></q></dt></tr></i><div id='WwbJp'><tfoot id='WwbJp'></tfoot><dl id='WwbJp'><fieldset id='WwbJp'></fieldset></dl></div>
          <bdo id='WwbJp'></bdo><ul id='WwbJp'></ul>

        使用自定义字体显示时间问题

        时间:2023-09-08
          <tbody id='XFwzB'></tbody>

          <bdo id='XFwzB'></bdo><ul id='XFwzB'></ul>
        • <legend id='XFwzB'><style id='XFwzB'><dir id='XFwzB'><q id='XFwzB'></q></dir></style></legend>
          1. <tfoot id='XFwzB'></tfoot>

              <small id='XFwzB'></small><noframes id='XFwzB'>

              <i id='XFwzB'><tr id='XFwzB'><dt id='XFwzB'><q id='XFwzB'><span id='XFwzB'><b id='XFwzB'><form id='XFwzB'><ins id='XFwzB'></ins><ul id='XFwzB'></ul><sub id='XFwzB'></sub></form><legend id='XFwzB'></legend><bdo id='XFwzB'><pre id='XFwzB'><center id='XFwzB'></center></pre></bdo></b><th id='XFwzB'></th></span></q></dt></tr></i><div id='XFwzB'><tfoot id='XFwzB'></tfoot><dl id='XFwzB'><fieldset id='XFwzB'></fieldset></dl></div>

                • 本文介绍了使用自定义字体显示时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个数字时钟小部件,我想使用自定义字体来显示时间.我知道它不能在远程视图中完成,所以我获得了一些代码,将自定义字体呈现为位图,然后将其跨远程视图推送到图像视图.但是,我无法让它工作.到目前为止,这是我的代码:

                  I have a digital clock widget, and I want to use a custom font to display the time. I know that it can't be done in remoteviews, so I have obtained some code that renders the custom font to a bitmap and then pushes it across remoteviews to an imageview. However, I am unable to get it to work. This is my code so far:

                          public Bitmap buildUpdate(String time)
                      {
                              RemoteViews views = new RemoteViews(this.getPackageName(), R.layout.main);
                              Bitmap myBitmap = Bitmap.createBitmap(100, 50, 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(15);
                              myCanvas.drawText(time, 0, 20, paint);
                              views.setImageViewBitmap(R.id.TimeView, myBitmap);
                              return myBitmap;
                              }
                  
                      private void update() {
                          mCalendar.setTimeInMillis(System.currentTimeMillis());
                          final CharSequence date = DateFormat.format(mDateFormat, mCalendar);
                          final CharSequence day = DateFormat.format(mDayFormat, mCalendar);
                  //        final CharSequence time = DateFormat.format(mTimeFormat, mCalendar);
                          String time = (String) DateFormat.format(mTimeFormat, mCalendar);
                          RemoteViews views = new RemoteViews(getPackageName(), R.layout.main);
                          views.setTextViewText(R.id.Day, day);
                          views.setTextViewText(R.id.Date, date);
                  //        views.setTextViewText(R.id.Time, time);
                          buildUpdate(time);
                          ComponentName widget = new ComponentName(this, DigiClock.class);
                          AppWidgetManager manager = AppWidgetManager.getInstance(this);
                          manager.updateAppWidget(widget, views);
                      }
                  

                  感谢任何帮助.

                  推荐答案

                  我现在(在经验丰富的开发人员的帮助下)找到了如何让它工作.现在最终的代码是:

                  I have now found out (with the help of an experienced developer) how to get it to work. The final code now is:

                      private void update() {
                      mCalendar.setTimeInMillis(System.currentTimeMillis());
                      final CharSequence date = DateFormat.format(mDateFormat, mCalendar);
                      final CharSequence day = DateFormat.format(mDayFormat, mCalendar);
                      String time = (String) DateFormat.format(mTimeFormat, mCalendar);
                      RemoteViews views = new RemoteViews(getPackageName(), R.layout.main);
                      views.setTextViewText(R.id.Day, day);
                      views.setTextViewText(R.id.Date, date);
                      views.setImageViewBitmap(R.id.TimeView, buildUpdate(time));
                      ComponentName widget = new ComponentName(this, DigiClock.class);
                      AppWidgetManager manager = AppWidgetManager.getInstance(this);
                      manager.updateAppWidget(widget, views);
                  }
                  
                      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;
                   }
                  

                  这篇关于使用自定义字体显示时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 android 应用程序中创建小部件?(使用 App Widget Host 类?) 下一篇:如何在应用小部件中为 Android AnalogClock 设置时间?

                  相关文章

                  <i id='A2b3s'><tr id='A2b3s'><dt id='A2b3s'><q id='A2b3s'><span id='A2b3s'><b id='A2b3s'><form id='A2b3s'><ins id='A2b3s'></ins><ul id='A2b3s'></ul><sub id='A2b3s'></sub></form><legend id='A2b3s'></legend><bdo id='A2b3s'><pre id='A2b3s'><center id='A2b3s'></center></pre></bdo></b><th id='A2b3s'></th></span></q></dt></tr></i><div id='A2b3s'><tfoot id='A2b3s'></tfoot><dl id='A2b3s'><fieldset id='A2b3s'></fieldset></dl></div>
                • <small id='A2b3s'></small><noframes id='A2b3s'>

                  1. <legend id='A2b3s'><style id='A2b3s'><dir id='A2b3s'><q id='A2b3s'></q></dir></style></legend>

                      <tfoot id='A2b3s'></tfoot>

                        <bdo id='A2b3s'></bdo><ul id='A2b3s'></ul>