1.软键盘处理方式
//关闭软键盘
private void hintSoftInput() {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if(imm != null && imm.isActive()&&getCurrentFocus()!=null){
if (getCurrentFocus().getWindowToken()!=null) {
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}
//如果显示则隐藏,如果隐藏则显示
private void changeSoftInput() {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
// 得到InputMethodManager的实例
if (imm.isActive()) {
// 如果开启
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
2.包含虚拟键盘的高度处理
//判断是否有虚拟键盘
@SuppressLint("NewApi")
public static boolean checkDeviceHasNavigationBar(Context activity) {
//通过判断设备是否有返回键、菜单键(不是虚拟键,是手机屏幕外的按键)来确定是否有navigation bar
boolean hasMenuKey = ViewConfiguration.get(activity)
.hasPermanentMenuKey();
boolean hasBackKey = KeyCharacterMap
.deviceHasKey(KeyEvent.KEYCODE_BACK);
if (!hasMenuKey && !hasBackKey) {
// 做任何你需要做的,这个设备有一个导航栏
return true;
}
return false;
}
//获取虚拟键盘高度
public static int getNavigationBarHeight(Context activity) {
Resources resources = activity.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height",
"dimen", "android");
//获取NavigationBar的高度
int height = resources.getDimensionPixelSize(resourceId);
return height;
}
3.让图片显示在状态栏上
分别创建values、values-v19、values-v21三个目录,分别在三个目录下创建styles.xml文件,依次添加下面代码
-value-
<style name="TranslucentSystemBar" parent="Theme.AppCompat.Light.NoActionBar"/>
-values-v19-
<style name="TranslucentSystemBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
-values-v21
<style name="TranslucentSystemBar" parent="Theme.AppCompat.Light.NoActionBar" >
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<!--Android 5.x 开始需要把状态栏颜色设为透明,否则会呈现系统默认的灰色-->
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
最后在布局页面的根布局添加
android:fitsSystemWindows="false"
在Manifest中添加主题样式
android:theme="@style/TranslucentSystemBar"
4.recycleView分组布局可参照
https://blog.csdn.net/xfhy_/article/details/78328983
5.A->B->C->D 界面依次跳转后,要从D按返回跳转B
在Intent中加入
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);//隔级跳转
可跳转中将C出栈。
6.列表水波纹样式 系统自带样式
android:background="?android:attr/selectableItemBackground"