获取activty title bar:

TextView actionTitle = (TextView) findViewById(com.android.internal.R.id.action_bar_title);

View actionTitle = getWindow().getDecorView().findViewById(getResources().getIdentifier("android:id/action_bar_title", null, null));

private static int flagsDate = DateUtils.FORMAT_SHOW_DATE; private static int flagsTime = DateUtils.FORMAT_SHOW_TIME ; private static int flagsWeek = DateUtils.FORMAT_SHOW_WEEKDAY; String dateStr = (String)DateUtils.formatDateTime(context, System.currentTimeMillis(), flagsDate);//5月11日 String timeStr = (String)DateUtils.formatDateTime(context, System.currentTimeMillis(), flagsTime);//16:40 String weekStr = (String)DateUtils.formatDateTime(context, System.currentTimeMillis(), flagsWeek);//星期二

12小时格式时,获取上午还是下午:

String smPmStr = DateUtils.getAMPMString(Calendar.getInstance().get(Calendar.AM_PM));//上午(下午)

12小时时间格式时,只显示时间,不显示“上午“这样的字符串:

private final static String M12 = "h:mm"; private final static String M24 = "kk:mm"; formatTime = android.text.format.DateFormat.is24HourFormat(context)? M24 : M12; String timeStr = (String) DateFormat.format(formatTime,System.currentTimeMillis());

将系统当前事件,转化为所需格式:

long dateTaken = System.currentTimeMillis(); if (dateTaken != 0) { String datetime = DateFormat.format("yyyy:MM:dd kk:mm:ss", dateTaken).toString(); Log.e(TAG,"datetime : " + datetime); }

如果为今天,则显示时间,如果不是今天则显示日期

private String getDate(long dateTime) { int flags = 0; String date = ""; if (DateUtils.isToday(dateTime)) { flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_24HOUR; date = (String)DateUtils.formatDateTime(mContext, dateTime, flags); } else { flags = DateUtils.FORMAT_SHOW_DATE; date = (String)DateUtils.formatDateTime(mContext, dateTime, flags); } return date; }

在源码短信息模块中MessageUtils.java中有这样一个函数,与上面的功能相同:

public static String formatTimeStampString(Context context, long when, boolean fullFormat) { Time then = new Time(); then.set(when); Time now = new Time(); now.setToNow(); // Basic settings for formatDateTime() we want for all cases. int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_CAP_AMPM; // If the message is from a different year, show the date and year. if (then.year != now.year) { format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE; } else if (then.yearDay != now.yearDay) { // If it is from a different day than today, show only the date. format_flags |= DateUtils.FORMAT_SHOW_DATE; } else { // Otherwise, if the message is from today, show the time. format_flags |= DateUtils.FORMAT_SHOW_TIME; } // If the caller has asked for full details, make sure to show the date // and time no matter what we've determined above (but still make showing // the year only happen if it is a different year from today). if (fullFormat) { format_flags |= (DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); } return DateUtils.formatDateTime(context, when, format_flags); }

软键盘显示消失及取反

InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); View view = getCurrentFocus(); if (view != null){ // imm.showSoftInput(view, 0); //显示软键盘 imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); // imm.hideSoftInputFromWindow(view.getWindowToken(), 0);//隐藏软键盘 // InputMethodManager.HIDE_NOT_ALWAYS); }

或者

getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

或者

public void hideInputMethod() { InputMethodManager imm = getInputMethodManager(); if (imm != null) { imm.hideSoftInputFromWindow(getWindowToken(), 0); } }

public void showInputMethod() { InputMethodManager imm = getInputMethodManager(); if (imm != null) { imm.showSoftInput(this, 0); } }

更多相关文章

  1. Android 时间对象操作工具类
  2. Android 字符串格式化 千位符
  3. 使Android原生时间选择器样式为滚轮
  4. Android软键盘手动显示、隐藏、布局上移和EditText上移
  5. (20120808)(01)android菜单与对话框--之日期及时间选择对话框
  6. Android-- 输入法键盘控制
  7. Android中获取时间
  8. Android获取系统时间
  9. EditText失去焦点隐藏软键盘

随机推荐

  1. 推荐给Android开发者的抢手书单
  2. Android消息机制之ThreadLocal浅析
  3. android中SELINUX规则分析和语法简介
  4. 解决Android(安卓)SDK Manager不能更新的
  5. Android(安卓)Weak Handler:可以避免内存
  6. Android多线程下载远程图片
  7. Android(安卓)轻松实现语音识别的完整代
  8. Android之隐式意图(Intent)如何查找匹配
  9. [置顶] Android学习系列-Android中解析xm
  10. Java vs. Kotlin:应该使用Kotlin进行Andro