您的位置:首页 > 移动开发 > Android开发

android 日期时间格式转换;软键盘显示消失;获取系统title

2011-01-26 10:52 1066 查看
获取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 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());


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

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中有这样一个函数,与上面的功能相同:

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 showInputMethod() {
InputMethodManager imm = getInputMethodManager();
if (imm != null) {
imm.showSoftInput(this, 0);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐