当前位置:   article > 正文

Android 时钟TextClock 使用及源码分析,2024Android开发社招面试总结+解答分享_android textclock

android textclock

android:textSize=“@dimen/text_size_16”

android:padding=“@dimen/dimen_10”/>

主界面代码

public class TextClockActivity extends AppCompatActivity {

private TextClock tc_timeText_12,tc_dateText_12,tc_timeText_24,tc_dateText_24;

private TextView tv_12hour,tv_24hour,tv_is24HourModeEnabled;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_textview_textclock);//加载布局文件

initView();

}

private void initView() {

tv_is24HourModeEnabled = findViewById(R.id.tv_is24HourModeEnabled);

tc_timeText_12 = findViewById(R.id.tc_timeText_12);

tc_dateText_12 = findViewById(R.id.tc_dateText_12);

tv_12hour = findViewById(R.id.tv_12hour);

//setTimeZone使用(UTC-7)无效,

//原因:源码未对UTC+(-)进行处理,下面有具体的源码分析

tc_timeText_12.setTimeZone(“America/Los_Angeles”);//有效

tc_dateText_12.setTimeZone(“America/Los_Angeles”);//有效

//tc_timeText_12.setTimeZone(“GMT+7:00”);//有效

//tc_dateText_12.setTimeZone(“GMT+7:00”);//有效

tc_dateText_12.setFormat24Hour(“HH:mm”);

tc_dateText_12.setFormat12Hour(“yyyy/MM/dd E”);

// EEEE:星期五 ;E/EE/EEE:周五;a:上午/下午

tc_dateText_12.setFormat24Hour(“yyyy年MM月dd日 EEEE aa HH:mm:ss”);

String format12 = “\n12小时模式格式:”+tc_timeText_12.getFormat12Hour();

format12 = format12+“\n24小时模式格式:”+tc_timeText_12.getFormat24Hour();

format12 = format12+“\n时区:”+tc_timeText_12.getTimeZone();

tv_12hour.setText(“Format:”+format12);

tc_timeText_24 = findViewById(R.id.tc_timeText_24);

tc_dateText_24 = findViewById(R.id.tc_dateText_24);

tv_24hour = findViewById(R.id.tv_24hour);

String format = “\n24小时模式格式:”+tc_timeText_24.getFormat24Hour();

format = format+“\n12小时模式格式:”+tc_timeText_24.getFormat12Hour();

format = format+“\n时区:”+tc_timeText_24.getTimeZone();

String timeZome =TimeZone

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/920665
推荐阅读
相关标签
  

闽ICP备14008679号