简体   繁体   中英

Change font size of TextView on AppWidget

From my configure activity the user can select his/hers desired font size of the widget. I set the font size like this:

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setFloat(R.id.tvConfigInput, "setTextSize", 25);

But I do not how to update the Widget with the selected size

Any suggestions?

Thanks

You have to use your AppWidgetManager.For example in onReceive() method of your AppWidgetProvider do some things like this:

@Override
public void onReceive(Context context, Intent intent) {
    views = new RemoteViews(context.getPackageName(),
                    R.layout.widget);
    AppWidgetManager mManager = AppWidgetManager.getInstance(context);
    ComponentName cn = new ComponentName(context,YourAppWidgetProvider.class);
    ...
    mManager.updateAppWidget(cn, views);

}

Here YourAppWidgetProvider is name of class that extends AppWidgetProvider .

What you have should work, as setTextSize() is a RemotableViewMethod (at least in the current source code) and therefore should work with RemoteViews .

First, try your app widget on an Android 4.2 emulator and see if it works. If it does, then the answer is that setTextSize() is usable on Android 4.2, is not usable on whatever environment you originally tried, and should become usable somewhere in between them.

Otherwise, make sure that you are actually updating the app widget, using AppWidgetManager and methods like updateAppWidget() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM