获取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);
- }
- }
相关推荐
android edittext不弹出软键盘三种方法“: 方法一: 在AndroidMainfest.xml中选择哪个activity,设置windowSoftInputMode属性为adjustUnspecified|stateHidden 例如: <activity android:name=".Main" android:...
android自定义软键盘键盘 系统键盘源码 两款android软件键盘 供大家参考学习
在软键盘弹出后随即弹出自定义的PopuWindow在其上方,里面还给PopuWindow加入了显示 和消失的动画,另外实现了对软键盘显示和隐藏状态的监听,以及对其高度的测量,需要做些逻辑处理的话可以直接在里面写相关的代码...
Unity3D android 拉起android软键盘 最近公司项目有一个手机VR展厅业务,用U3D做VR场景还可以做到,后面要加个2D的线下预定页面,就涉及到3D 2D界面转换,首先考虑u3d作为插件,不考虑升级客户端,更新U3D资源来升级...
检测软键盘是否显示或隐藏的功能。blog:http://blog.csdn.net/hehaiminginadth/article/details/48435703
Android自定义软键盘,在Keyboard的基础上稍微修改了一下,从键盘焦点效果到键盘布局,都是新风格。
android中监听软键盘的弹出与隐藏,并获取软键盘的高度,在adjustPan,adjustResize,adjustUnspecified下都可以
在开发时遇到一个问题,需要对软...但是由于android不直接提供对软键盘打开与关闭操作的监听器,所以必须自己来写一个关于软键盘打开/关闭的监听器。 原理是通过对OnGlobalLayoutListener()来实现对软键盘的状态监听器
在Android应用中有时会需要获取软键盘的状态(即软键盘是显示还是隐藏)和软键盘的高度。这里列举了一些可能的应用场景。 场景一 当软键盘显示时,按下返回键应当是收起软键盘,而不是回退到上一个界面,但部分...
软键盘弹出之后,计算软键盘的高度,将自定义的View设置于软键盘之上。代码重点计算了如何让软键盘显示与隐藏,并且,还解决了如何点击软键盘与自定义View 之外的区域,让软键盘隐藏而不会与其他控件的点击事件冲突...
Android 底部控件随软键盘弹出而上移demo
最近在做android4.4.4 wifi密码自定义键盘,通过网上的资料...带光标的软键盘,同时屏蔽系统的软键盘,键盘是弹出框式,可通过代码或者layout来更改。 此apk需要通过.mk编译才可使用,因为里面有的方法是api没有公开。
android 关闭软键盘
NULL 博文链接:https://dadi520.iteye.com/blog/2211109
android软键盘上添加一个按钮
android自带的输入法,在软键盘上实现焦点移动,支持上下左右按键,并支持回车输入,文档以LatinIME为例
Android自定义输入法软键盘,博客地址: https://blog.csdn.net/DeMonliuhui/article/details/84589936
android解决软键盘遮挡输入框的示例代码