我使用以下代码显示数字时钟
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Analog Clock"
android:textAppearance="?android:attr/textAppearanceLarge" />
<AnalogClock
android:id="@+id/analogClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Digital Clock"
android:textAppearance="?android:attr/textAppearanceLarge" />
<DigitalClock
android:id="@+id/digitalClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DigitalClock" />
</LinearLayout>
public class MyAndroidAppActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AnalogClock ac = (AnalogClock) findViewById(R.id.analogClock1);
//what can i do with AnalogClock?
DigitalClock dc = (DigitalClock) findViewById(R.id.digitalClock1);
//what can i do with DigitalClock also? for display only
}
}
以上代码工作正常但在Kitkat版本中它没有显示秒请帮我如何启用秒
这里我附上我在nexus 7中截取的截图
答案 0 :(得分:1)
对不起我的英文,谷歌翻译。我的手机就在这里。
反编译framework.jar
添加到framework \ smali \ android \ widget \ DigitalClock.smali
# static fields
.field private static final m12:Ljava/lang/String; = "h:mm:ss aa"
.field private static final m24:Ljava/lang/String; = "k:mm:ss"
.method private get24HourMode()Z
.locals 1
.prologue
.line 1090
invoke-virtual {p0}, Landroid/widget/DigitalClock;->getContext()Landroid/content/Context;
move-result-object v0
invoke-static {v0}, Landroid/text/format/DateFormat;->is24HourFormat(Landroid/content/Context;)Z
move-result v0
return v0
.end method
方法 .method private setFormat()V 完全替换
.method private setFormat()V
.locals 1
.prologue
.line 1130
invoke-direct {p0}, Landroid/widget/DigitalClock;->get24HourMode()Z
move-result v0
if-eqz v0, :cond_0
.line 1140
const-string v0, "k:mm:ss"
iput-object v0, p0, Landroid/widget/DigitalClock;->mFormat:Ljava/lang/String;
.line 1180
:goto_0
return-void
.line 1160
:cond_0
const-string v0, "h:mm:ss aa"
iput-object v0, p0, Landroid/widget/DigitalClock;->mFormat:Ljava/lang/String;
goto :goto_0
.end method