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

获取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));

privatestaticintflagsDate = DateUtils.FORMAT_SHOW_DATE;

privatestaticintflagsTime = DateUtils.FORMAT_SHOW_TIME ;

privatestaticintflagsWeek = 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小时时间格式时,只显示时间,不显示“上午“这样的字符串:

privatefinalstaticString M12 ="h:mm";

privatefinalstaticString M24 ="kk:mm";

formatTime = android.text.format.DateFormat.is24HourFormat(context)? M24 : M12;

String timeStr = (String) DateFormat.format(formatTime,System.currentTimeMillis());

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

longdateTaken = System.currentTimeMillis();

if(dateTaken !=0) {

String datetime = DateFormat.format("yyyy:MM:dd kk:mm:ss", dateTaken).toString();

Log.e(TAG,"datetime : "+  datetime);

}

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

privateString getDate(longdateTime)

{

intflags =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);

}

returndate;

}

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

publicstaticString formatTimeStampString(Context context,longwhen,booleanfullFormat) {

Time then = newTime();

then.set(when);

Time now = newTime();

now.setToNow();

// Basic settings for formatDateTime() we want for all cases.

intformat_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;

} elseif(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);

}

returnDateUtils.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);

或者

publicvoidhideInputMethod() {

InputMethodManager imm = getInputMethodManager();

if(imm !=null) {

imm.hideSoftInputFromWindow(getWindowToken(), 0);

}

}

publicvoidshowInputMethod() {

InputMethodManager imm = getInputMethodManager();

if(imm !=null) {

imm.showSoftInput(this,0);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值