android偏门知识小节
2015-12-24 17:55
393 查看
1、dp转px,使用函数转换
Math.round(TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
10, getResources()
.getDisplayMetrics()));
2、系统导航栏:判读是否含有,获取高度
private boolean hasSystemNavigationBar() {
if (Build.VERSION.SDK_INT < 11) {
// 3.0加入的方法,3.0之前不处理
return false;
}
// //通过判断设备是否有返回键、菜单键(不是虚拟键,是手机屏幕外的按键)来确定是否有navigation bar
// boolean hasMenuKey = ViewConfiguration.get(this)
// .hasPermanentMenuKey();
// boolean hasBackKey = KeyCharacterMap
// .deviceHasKey(KeyEvent.KEYCODE_BACK);
//
// if (!hasMenuKey && !hasBackKey) {
// // 做任何你需要做的,这个设备有一个导航栏
// return true;
// }
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
if (hasBackKey && hasHomeKey) {
// 有虚拟按键
return true;
} else {
// 没有有虚拟按键:99%可能。
return false;
}
// return false;
}
public int getSystemNavigationBarHeight() {
Resources resources = this.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height",
"dimen", "android");
//获取NavigationBar的高度
int height = resources.getDimensionPixelSize(resourceId);
return height;
}
3、监听软键盘:onSizeChanged方法应该也可用
parentLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mNavigationLayout.getLayoutParams();
if(bottom != 0 && oldBottom != 0 && bottom != oldBottom && layoutParams !=null){
if (height != 0 && bottom - oldBottom < 0 && oldBottom - bottom == height) {
// 如果有布局弹出,弹出高度,小于系统虚拟按键的高度,视为虚拟按键弹出,其他视为键盘
return;
}
if (bottom < oldBottom) {
4、
Math.round(TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
10, getResources()
.getDisplayMetrics()));
2、系统导航栏:判读是否含有,获取高度
private boolean hasSystemNavigationBar() {
if (Build.VERSION.SDK_INT < 11) {
// 3.0加入的方法,3.0之前不处理
return false;
}
// //通过判断设备是否有返回键、菜单键(不是虚拟键,是手机屏幕外的按键)来确定是否有navigation bar
// boolean hasMenuKey = ViewConfiguration.get(this)
// .hasPermanentMenuKey();
// boolean hasBackKey = KeyCharacterMap
// .deviceHasKey(KeyEvent.KEYCODE_BACK);
//
// if (!hasMenuKey && !hasBackKey) {
// // 做任何你需要做的,这个设备有一个导航栏
// return true;
// }
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
if (hasBackKey && hasHomeKey) {
// 有虚拟按键
return true;
} else {
// 没有有虚拟按键:99%可能。
return false;
}
// return false;
}
public int getSystemNavigationBarHeight() {
Resources resources = this.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height",
"dimen", "android");
//获取NavigationBar的高度
int height = resources.getDimensionPixelSize(resourceId);
return height;
}
3、监听软键盘:onSizeChanged方法应该也可用
parentLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mNavigationLayout.getLayoutParams();
if(bottom != 0 && oldBottom != 0 && bottom != oldBottom && layoutParams !=null){
if (height != 0 && bottom - oldBottom < 0 && oldBottom - bottom == height) {
// 如果有布局弹出,弹出高度,小于系统虚拟按键的高度,视为虚拟按键弹出,其他视为键盘
return;
}
if (bottom < oldBottom) {
4、
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories