MaterialDrawer 设置选定的配置文件

MaterialDrawer set selected profile

我使用 Mike Penz 的 MaterialDrawer 库。

在我的 OnCreate 中,配置文件从 linkedHashMap 添加到抽屉中。选择配置文件后,新选择的配置文件将保存在 sharedPreference 中。

我的问题:如果我再次启动该应用程序,我如何将名称存储在 sharedPreference 中的配置文件设置为选中?

编辑:没有标识符?或者这是不可能的?

MaterialDrawer需要一个identifier给它的元素,这样你就可以重新select它们(并且Drawer 本身可以在配置更改时重新 select 它们)。

只需提供任何 ID。你可以使用这样的东西:

private static long hashString64Bit(CharSequence str) {
    long result = 0xcbf29ce484222325L;
    final int len = str.length();
    for (int i = 0; i < len; i++) {
        result ^= str.charAt(i);
        result *= 0x100000001b3L;
    }
    return result;
}

为您的 string 生成长标识符,或者生成某种哈希码。