相关疑难解决方法(0)

如何在窗口小部件中使用自定义字体?

我有一个数字时钟小部件.如何使用资产/字体中的自定义字体作为显示时钟的textview中的默认字体?

这是我的代码:

    package android.tristan.widget.digiclock;

import java.util.Calendar;

import android.app.PendingIntent;
import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.os.Vibrator;
import android.text.format.DateFormat;
import android.widget.RemoteViews;


public class DigiClock extends AppWidgetProvider {

    @Override
    public void onDisabled(Context context) {
        super.onDisabled(context);
        context.stopService(new Intent(context, UpdateService.class));
    }
    public void onReceive(Context context, Intent intent)
    {
        super.onReceive(context, intent);

        if(intent.getAction().equals("android.tristan.widget.digiclock.CLICK"))
        {
          Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
          vibrator.vibrate(50);           
            final Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN, null);
            alarmClockIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            final ComponentName cn = new ComponentName("com.android.deskclock", …
Run Code Online (Sandbox Code Playgroud)

android widget typeface

39
推荐指数
4
解决办法
2万
查看次数

每当我们想要在应用程序中更改字体时,我们是否必须复制字体TTF

以前,为了让我的应用程序在Gingerbread设备及以上版本中可行,我必须将Robotto字体资源复制到资产文件夹中.这是因为Gingerbread没有自带Robotto字体.

在此输入图像描述

但是,让我说,我决定只将我的应用程序部署到Jelly Bean设备.

  1. 我是否仍需要手动将字体资源复制到我的资产文件夹中?我可以使用系统本身的字体资源吗?这是鼓励的吗?我在想,不提供我自己的字体文件,我可以让我的应用程序更小.
  2. 这是TypeFace从资产文件夹获取的代码.

    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");

    如果我想TypeFace直接从系统本身获取,怎么样?

android

4
推荐指数
1
解决办法
1924
查看次数

标签 统计

android ×2

typeface ×1

widget ×1