最近一直在头疼怎样在修改Settings-----Date&Time---Choose data format 后通知更新桌面时钟 AppWidget的日期格式跟着Setting的改变而改变...
想实现的效果就是如下:
原先日期格式是这样,
当点击修改Settings-----Date&Time---Choose data format,
想动态实现,就有点不知道怎么解决了,
这个布局其实是一个TextClock
<TextClock android:id="@+id/date" style="@style/label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:format12Hour="@string/abbrev_wday_month_day_no_year" android:format24Hour="@string/abbrev_wday_month_day_no_year" android:gravity="center" android:textColor="@color/clock_white" />
<?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2007 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- 字符串匹配的锁定屏幕显示日期的格式. MM/dd/yyy--> <string name="abbrev_wday_month_day_no_year">dd-MM-yyyy</string> <!-- Format for describing the date, for accessibility. --> <string name="full_wday_month_day_no_year">EEEE, MMMM d</string> <!-- Default clock style. --> <string name="default_clock_style">digital</string> </resources>
第一种解决方法,属于治标不治本的方法,这种方法是静态修改abbrev_wday_month_day_no_year的值为想要的日期格式,
比如修改为:<string name="abbrev_wday_month_day_no_year">EE-d-MMM-yyyy</string>
这个有点不靠谱,或者修改为如下格式
日期格式的值的方法有如下:
<string-array name="date_format_values" translatable="false"> <!-- The blank item means to use whatever the locale calls for. --> <item></item> <item>MM-dd-yyyy</item> <item>dd-MM-yyyy</item> <item>yyyy-MM-dd</item> <item>EE-MMM-d-yyyy</item> <item>EE-d-MMM-yyyy</item> <item>yyyy-MMM-d-EE</item> </string-array>老大给的建议让重写TextView不用TextClock,可是自己水平有限重写的几次都没达到理想的效果。。。。
网上收到的一些方法有如下,自己是小菜鸟一枚,看了好久还是没有解决掉这个问题,希望有大神能够帮助一下...