- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 KitKat 中,以下日期格式化程序会产生错误的结果。是我还是 KitKat?
对于除 KitKat 之外的所有版本,以下代码生成预期的“4 月 27 日”。但是,在 KitKat 上,它会记录“A 27”。我检查了调试器以验证这不是布局问题 - SimpleDataFormat 创建的字符串是“A 27”。
SimpleDateFormat dateOnyFormat = new SimpleDateFormat(
"MMMMM dd", Locale.US);
Date startDate = new Date();
String startTimeFormatted = dateOnyFormat.format(startDate);
Log.i("DateTest","startTimeFormatted: "+startTimeFormatted);
有谁知道为什么 KitKat 格式会生成月份的第一个字母,而不是月份?
有什么解决办法吗?
这是插入了此代码的 ADT 的默认 Android 主要项目。
package com.example;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import com.example.util.SystemUiHider;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
/**
* An example full-screen activity that shows and hides the system UI (i.e. status bar and navigation/system bar) with
* user interaction.
*
* @see SystemUiHider
*/
public class MainActivity extends Activity {
/**
* Whether or not the system UI should be auto-hidden after {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
*/
private static final boolean AUTO_HIDE = true;
/**
* If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after user interaction before hiding the system
* UI.
*/
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
/**
* If set, will toggle the system UI visibility upon interaction. Otherwise, will show the system UI visibility upon
* interaction.
*/
private static final boolean TOGGLE_ON_CLICK = true;
/**
* The flags to pass to {@link SystemUiHider#getInstance}.
*/
private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;
/**
* The instance of the {@link SystemUiHider} for this activity.
*/
private SystemUiHider mSystemUiHider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final View controlsView = findViewById(R.id.fullscreen_content_controls);
final View contentView = findViewById(R.id.fullscreen_content);
SimpleDateFormat dateOnyFormat = new SimpleDateFormat(
"MMMMM dd", Locale.US);
Date startDate = new Date();
String startTimeFormatted = dateOnyFormat.format(startDate);
Log.i("DateTest","startTimeFormatted: "+startTimeFormatted);
// Set up an instance of SystemUiHider to control the system UI for
// this activity.
mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
mSystemUiHider.setup();
mSystemUiHider.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
// Cached values.
int mControlsHeight;
int mShortAnimTime;
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public void onVisibilityChange(boolean visible) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
// If the ViewPropertyAnimator API is available
// (Honeycomb MR2 and later), use it to animate the
// in-layout UI controls at the bottom of the
// screen.
if (mControlsHeight == 0) {
mControlsHeight = controlsView.getHeight();
}
if (mShortAnimTime == 0) {
mShortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
}
controlsView.animate().translationY(visible ? 0 : mControlsHeight).setDuration(mShortAnimTime);
} else {
// If the ViewPropertyAnimator APIs aren't
// available, simply show or hide the in-layout UI
// controls.
controlsView.setVisibility(visible ? View.VISIBLE : View.GONE);
}
if (visible && AUTO_HIDE) {
// Schedule a hide().
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
}
});
// Set up the user interaction to manually show or hide the system UI.
contentView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (TOGGLE_ON_CLICK) {
mSystemUiHider.toggle();
} else {
mSystemUiHider.show();
}
}
});
// Upon interacting with UI controls, delay any scheduled hide()
// operations to prevent the jarring behavior of controls going away
// while interacting with the UI.
findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Trigger the initial hide() shortly after the activity has been
// created, to briefly hint to the user that UI controls
// are available.
delayedHide(100);
}
/**
* Touch listener to use for in-layout UI controls to delay hiding the system UI. This is to prevent the jarring
* behavior of controls going away while interacting with activity UI.
*/
View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (AUTO_HIDE) {
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
return false;
}
};
Handler mHideHandler = new Handler();
Runnable mHideRunnable = new Runnable() {
@Override
public void run() {
mSystemUiHider.hide();
}
};
/**
* Schedules a call to hide() in [delay] milliseconds, canceling any previously scheduled calls.
*/
private void delayedHide(int delayMillis) {
mHideHandler.removeCallbacks(mHideRunnable);
mHideHandler.postDelayed(mHideRunnable, delayMillis);
}
}
最佳答案
因为那是how it is documented to behave .使用 MMMM
(四个 M)作为完整的月份名称。
关于android - SimpleDateFormat 不在 KitKat 中生成月份名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23328353/
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 2年前关闭。 Improve thi
Kitkat HCE(NFC) 设备可以与另一台 Kitkat HCE(NFC) 设备通信吗? 我想编写应用程序将数据从一台 Kitkat HCE(NFC) 设备传输到另一台 Kitkat HCE(N
我在 KitKat 上收到以下错误,但在 Android M 及更高版本上没有问题: 2145-2145/com.cafeapps.stroydownloader E/dalvikvm: Could
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
问题 我的应用程序支持 4.0+,它完全是关于文件处理的。它适用于除 Kitkat 之外的所有 Android 版本。 在 Kitkat 中,我的应用无法修改或写入 SD 卡中的任何文件。但我看到各种
我有一个从我的服务器转换时间的函数,它在 android api 24 上运行良好,但现在我在 KitKat (Api 19) 上进行测试,时间转换无法正常工作。两个设备接收相同的数据,但转换不一样。
到目前为止,当使用 LocationClient 获取用户的最后已知位置时,我没有遇到任何问题,例如在 Jelly Bean 上进行测试。 我有一部 KitKat 手机进行测试,我发现在设置 -> 位
该问题仅在使用新的 WebView 机制的 KitKat 上出现。 基本上我加载了 12 张图片,一张接一张地连续加载。我希望 WebView 加载一行中的所有图像并自动缩放 webView 以覆盖整
我正在开发一个类似于 SMS 黑名单/白名单的应用程序。它现在不是 SMS 应用程序。 目标是: 如果该号码在黑名单中,它会阻止用户接收/发送短信,并且不会出现在他的短信应用程序中。 如果号码在白名单
因此,在我正在构建的应用程序中,我获取手机中的所有联系人并将其显示在 ListView 中。一切正常,直到我将手机 (HTC One) 从 4.1.2 升级到 4.4.2。我不再获取联系人的图像/个人
我在我的应用程序中使用了开关小部件。当我在 Lollipop 上运行应用程序时,它运行良好。但是当我运行 kitkat 版本时,它会崩溃。 xml设计: switchdb.xml
我正在尝试加载图像。当我使用 API 18 或更低版本时,这很好用,但如果我使用 API 19 (Kitkat),则会出现安全问题......我不确定如何解决这个,但是 cursorloader 给我
我收到 Android 4.4.4 用户关于我的动画呈现奇怪问题的投诉。到目前为止,我没有收到任何其他 Android 版本的投诉。我也无法在模拟器中复制错误(或者在我的 Nexus 7 上,这两个投
大家好,我正在开发一个消息应用程序,并按照谷歌博客 link here 的所有说明进行操作 它工作得很好。但是当我的应用程序作为默认消息应用程序工作时我遇到问题我想将消息保存在我的应用程序数据库以及设
我正在尝试利用新的 KitKat 半透明系统栏,在我的应用背景中获得全屏图像。 我无法确定正确的设置来获得我想要的行为。现在,我有一个 ViewPager 和三个 Fragment,每个由一个 Rel
我在Play商店发布的一些应用在android 4.4和onwords上崩溃了 相同的应用程序可在其他版本的Android上使用。 这个问题与os或其他有关吗? 最佳答案 是的,问题与操作系统有关。从
在你降级之前,我知道当你用谷歌搜索时,有与这个主题相关的类似问题。甚至它已经在 Stackoverflow 中得到了多次回答。 然而,尽管我阅读了所有这些主题,但它们都没有解决我的问题。我的代码适用于
我有一个Recyclerview。在它的适配器中,这就是我所拥有的: @Override public void onBindViewHolder(@NonNull ViewHolder holde
我正在 imageView 中查看来自 url 的图像,该代码适用于 android lollipop 和较新版本,但不适用于 android Kitkat 和旧版本,它返回空白图像而不是 url图片
我真的试过了,广播接收器没有收到新的短信广播。我在我的手机 4.4.4 上运行,我只想收听传入的消息,也就是说。
我是一名优秀的程序员,十分优秀!