【问题标题】:Why I can't get Settings.System.DATE_FORMAT in the LockScreen?为什么我无法在 LockScreen 中获取 Settings.System.DATE_FORMAT?
【发布时间】:2011-06-25 02:23:23
【问题描述】:

这是 android 中的 LockScreen 的一些代码。 日期格式为:

mDateFormatString = getContext().getString(R.string.full_wday_month_day_no_year);

我设置:

mDateFormatString =Settings.System.getString(getContext().getContentResolver(), Settings.System.DATE_FORMAT) ;

为什么我无法在 LockScreen 中获取 Settings.System.DATE_FORMAT?

private void resetStatusInfo(KeyguardUpdateMonitor updateMonitor) {
    mShowingBatteryInfo = updateMonitor.shouldShowBatteryInfo();
    mPluggedIn = updateMonitor.isDevicePluggedIn();
    mBatteryLevel = updateMonitor.getBatteryLevel();

    /* for dual sim, by jing.wang */
    mStatus[SimCardID.ID_ZERO.toInt()] = getCurrentStatus(updateMonitor.getSimState());
    if (isDualMode) {
        mStatus[SimCardID.ID_ONE.toInt()] = getCurrentStatus(updateMonitor.getSimState (SimCardID.ID_ONE));
        updateLayout(mStatus[SimCardID.ID_ZERO.toInt()], SimCardID.ID_ZERO, mStatus[SimCardID.ID_ONE.toInt()]);
        updateLayout(mStatus[SimCardID.ID_ONE.toInt()], SimCardID.ID_ONE, mStatus[SimCardID.ID_ZERO.toInt()]);
    } else {
        updateLayout(mStatus[SimCardID.ID_ZERO.toInt()]);
    }

    refreshBatteryStringAndIcon();
    refreshAlarmDisplay();

    mTimeFormat = DateFormat.getTimeFormat(getContext());
    mDateFormatString = getContext().getString(R.string.full_wday_month_day_no_year);

    refreshTimeAndDateDisplay();
    updateStatusLines();
}

编辑:我想修改锁屏密码。我想显示我在设置中设置的日期格式。但是现在我设置了日期格式“dd-MM-yyyy”,它不能在锁屏中显示。日期以 mDateFormatString 的格式显示。

mDateFormatString = getContext().getString(R.string.full_wday_month_day_no_year); 

这是refreshTimeAndDateDisplay的代码。

private void refreshTimeAndDateDisplay() {
    mDate.setText(DateFormat.format(mDateFormatString, new Date()));
} 

【问题讨论】:

    标签: android date-format


    【解决方案1】:

    你应该看看这个:How to use the date format that has been setup as default in Settings?(getDateFormatOrder给你用户的格式设置)

    【讨论】:

    • public static final char[] getDateFormatOrder (Context context) 自:API Level 3 获取存储为 char 数组的当前日期格式。该数组将包含 3 个元素(DATE、MONTH 和 YEAR),按用户的格式偏好指定的顺序排列。
    • 是的,如果你能准确解释你想要做什么......你想修改锁屏代码?或者你想在应用中做点什么?
    • 我要修改锁屏。我想显示我在设置中设置的日期格式。因为 mDateFormatString = getContext().getString(R.string.full_wday_month_day_no_year);私人无效 refreshTimeAndDateDisplay() { mDate.setText(DateFormat.format(mDateFormatString, new Date())); }
    猜你喜欢
    • 1970-01-01
    • 2018-12-24
    • 2020-04-12
    • 2022-08-24
    • 2014-03-09
    • 2020-06-26
    • 2019-04-03
    • 1970-01-01
    • 2020-04-18
    相关资源
    最近更新 更多