Android 如何将类别添加到SyncAdapter
我曾经尝试过谷歌的一个很好的例子,从一个Web服务同步联系人,效果很好。 这被称为SampleSyncAdapter,非常值得: 我成功地完成了所有操作,但在示例或文档中都找不到添加链接到自定义活动的类别的方法,与下面的屏幕截图完全相同: (我只有带有复选框的“同步帐户”选项) 因此,我的问题是:如何添加帐户设置类别?的答案为通用解决方案提供了一个新的解决方案。下面是如何修改源代码以添加自定义首选项(Android 2.3.4),如上面的屏幕截图所示:Android 如何将类别添加到SyncAdapter,android,settings,android-syncadapter,Android,Settings,Android Syncadapter,我曾经尝试过谷歌的一个很好的例子,从一个Web服务同步联系人,效果很好。 这被称为SampleSyncAdapter,非常值得: 我成功地完成了所有操作,但在示例或文档中都找不到添加链接到自定义活动的类别的方法,与下面的屏幕截图完全相同: (我只有带有复选框的“同步帐户”选项) 因此,我的问题是:如何添加帐户设置类别?的答案为通用解决方案提供了一个新的解决方案。下面是如何修改源代码以添加自定义首选项(Android 2.3.4),如上面的屏幕截图所示: 请记住,帐户管理器是作为系统进程运行的,
account\u preferences.xml
资源文件
- 实际首选项屏幕的android:key
值必须指定为
李>“帐户设置”
- 如果要将自定义首选项放入类别中,则需要 定义时关闭
标记;如果您将首选项类别
置于类别内,则当您单击首选项时,手机将崩溃首选项屏幕
- 如果要将自定义首选项放入类别中,则需要 定义时关闭
<activity android:label="Account Preferences" android:name=".AccountPreferences"
android:theme="@android:style/Theme.Dialog" android:excludeFromRecents="true" />
c。下面是带有硬编码字符串的首选项\u resources.xml
:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Privacy preferences"/>
<CheckBoxPreference android:key="privacy_contacts" android:defaultValue="true"
android:summary="Keep contacts private" android:title="Contacts"/>
<PreferenceCategory android:title="Outgoing"/>
<CheckBoxPreference android:key="allow_mail" android:defaultValue="true"
android:summary="Allow email" android:title="Email"/>
</PreferenceScreen>
<activity android:label="Account Preferences" android:name=".AccountPreferences"
android:theme="@android:style/Theme.Dialog" android:excludeFromRecents="true" />
public class AccountPreferences extends PreferenceActivity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.preferences_resources);
}
}
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Privacy preferences"/>
<CheckBoxPreference android:key="privacy_contacts" android:defaultValue="true"
android:summary="Keep contacts private" android:title="Contacts"/>
<PreferenceCategory android:title="Outgoing"/>
<CheckBoxPreference android:key="allow_mail" android:defaultValue="true"
android:summary="Allow email" android:title="Email"/>
</PreferenceScreen>