我有一个 PreferenceActivity,用户可以在其中选择 Widget 应用程序的 TextView 的大小。按下 Widget 时会调用该活动。我在 OnPause 中设置文本大小,但它不起作用。代码有问题吗?
public class WidgetSettings extends PreferenceActivity
{
private int mAppWidgetId = 0;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.widget_setttings_layout);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
}
@Override
protected void onPause()
{
super.onPause();
float textSize = Float.parseFloat(PreferenceManager.getDefaultSharedPreferences(this).getString("batteryTextSize", "12"));
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getBaseContext());
RemoteViews remoteView = new RemoteViews(getBaseContext().getPackageName(), R.layout.widget_layout);
remoteView.setFloat(R.id.textView1, "setTextSize", 22);
appWidgetManager.updateAppWidget(mAppWidgetId, remoteView);
}
}