getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏操作栏
super.onCreate(savedInstanceState);
getWindow().setEnterTransition(new Fade().setDuration(2000));
getWindow().setExitTransition(new Fade().setDuration(2000));
setContentView(R.layout.main);
t = findViewById(R.id.mainTextView1);
t2 = findViewById(R.id.mainTextView2);
handler.post(task);//立即调用
}
public void toBack(View v)
{
moveTaskToBack(false);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
}
@Override
protected void onResume()
{
/**
* 设置为横屏
*/
if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
super.onResume();
}
private Handler handler = new Handler();
private Runnable task =new Runnable() {
public void run()
{
// TODOAuto-generated method stub
handler.postDelayed(this, 1 * 1000);//设置延迟时间,此处是5秒
//需要执行的代码
timeNow = getNowDay("HH:mm");
todayNow = getNowDay("yyyy-MM-dd");
t.setText(timeNow);
t2.setText(todayNow);
}
};
/*获取当前时间
* @param timeFormat 时间格式
* @return 时间文本
*/
public String getNowDay(String timeFormat)
{
/**
* SimpleDateFormat 是一个以与语言环境有关的方式来格式化和解析日期的具体类(java.text.SimpleDateFormat)。
* 它允许进行格式化(日期 -> 文本)、解析(文本 -> 日期)和规范化。
*/
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timeFormat);
String dateString = simpleDateFormat.format(new Date()); //将给定的 Date 格式化为日期/时间字符串
return dateString;
}
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏操作栏
super.onCreate(savedInstanceState);
getWindow().setEnterTransition(new Fade().setDuration(2000));
getWindow().setExitTransition(new Fade().setDuration(2000));
setContentView(R.layout.main);
t = findViewById(R.id.mainTextView1);
t2 = findViewById(R.id.mainTextView2);
handler.post(task);//立即调用
}
public void toBack(View v)
{
moveTaskToBack(false);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
}
@Override
protected void onResume()
{
/**
* 设置为横屏
*/
if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
super.onResume();
}
private Handler handler = new Handler();
private Runnable task =new Runnable() {
public void run()
{
// TODOAuto-generated method stub
handler.postDelayed(this, 1 * 1000);//设置延迟时间,此处是5秒
//需要执行的代码
timeNow = getNowDay("HH:mm");
todayNow = getNowDay("yyyy-MM-dd");
t.setText(timeNow);
t2.setText(todayNow);
}
};
/*获取当前时间
* @param timeFormat 时间格式
* @return 时间文本
*/
public String getNowDay(String timeFormat)
{
/**
* SimpleDateFormat 是一个以与语言环境有关的方式来格式化和解析日期的具体类(java.text.SimpleDateFormat)。
* 它允许进行格式化(日期 -> 文本)、解析(文本 -> 日期)和规范化。
*/
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timeFormat);
String dateString = simpleDateFormat.format(new Date()); //将给定的 Date 格式化为日期/时间字符串
return dateString;
}