我有配置页面的小部件。 在将小部件添加到主屏幕时,我可以设置一些配置。
添加小部件后,在拖动的同时,我在屏幕的上方看到两个按钮: [编辑] | [删除] 我只能从主屏幕删除小部件。编辑按钮被禁用。
如何启用此“编辑”功能,以便在将小部件添加到屏幕后,可以在“[编辑]”位置拖动小部件以打开配置页面?
答案 0 :(得分:-1)
public WidgetConfiguration(Context context, int widgetId) {
this.context = context;
this.widgetId = widgetId;
}
public String getTitle() {
return getPrefs().getString(getFullKeyName("title"), null);
}
public SimpleDate getSimpleDate() {
int year, month, day;
SharedPreferences prefs = getPrefs();
year = prefs.getInt(getFullKeyName("date_year"), 0);
month = prefs.getInt(getFullKeyName("date_month"), 0);
day = prefs.getInt(getFullKeyName("date_day"), 0);
if (year == 0 || month == 0 || day == 0)
return null;
else
return new SimpleDate(year, month, day);
}
public void setTitle(String title) {
SharedPreferences.Editor editor = getPrefsEditor();
editor.putString(getFullKeyName("title"), title);
editor.commit();
}
public void setSimpleDate(SimpleDate date) {
SharedPreferences.Editor editor = getPrefsEditor();
int year = 0, month = 0, day = 0;
if (date != null) {
year = date.getYear();
month = date.getMonth();
day = date.getDay();
}
editor.putInt(getFullKeyName("date_year"), year);
editor.putInt(getFullKeyName("date_month"), month);
editor.putInt(getFullKeyName("date_day"), day);
editor.commit();
}
public void clear() {
setTitle(null);
setSimpleDate(null);
}
protected SharedPreferences getPrefs() {
return context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
}
protected String getFullKeyName(String keyName) {
return PREF_PREFIX + widgetId + "_" + keyName;
}
protected SharedPreferences.Editor getPrefsEditor() {
return getPrefs().edit();
}
https://play.google.com/store/apps/details?id=com.Free.daysleft