一、点击通知栏进入Activity,重新打开获取新Intent信息
重写onNewIntent
/**
* 重新打开进入获取新的intent信息
*
* @param intent
*/
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// TODO
// 用户处理在后台重新进入App,通知栏点击进入APP
}
}
二、在Android4.4以上系统底部聊天及评论框不能被系统输入法顶上去
package com.gzjiequan.rescuewithyou.util;
import android.app.Activity;
import android.graphics.Rect;
import android.view.View;
import android.widget.FrameLayout;
/**
* Android 4.4 键盘弹出高难度测量
*
* @author pc
*/
public class AndroidBug5497Workaround {
private int stateHeight;
public static void assistActivity(Activity activity) {
new AndroidBug5497Workaround(activity);
}
private View mChildOfContent;
private int usableHeightPrevious;
private FrameLayout.LayoutParams frameLayoutParams;
private AndroidBug5497Workaround(Activity activity) {
stateHeight = activity.getResources().getDimensionPixelSize(activity.getResources().getIdentifier("status_bar_height", "dimen", "android"));
FrameLayout content = activity.findViewById(android.R.id.content);
mChildOfContent = content.getChildAt(0);
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(() -> possiblyResizeChildOfContent());
frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
}
/**
* 键盘高度:usableHeightSansKeyboard ,无键盘的高度/屏幕高度:usableHeightSansKeyboard 可视内容高度:usableHeightNow
*/
private void possiblyResizeChildOfContent() {
int usableHeightNow = computeUsableHeight();
if (usableHeightNow != usableHeightPrevious) {
int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
int heightDifference = usableHeightSansKeyboard - usableHeightNow;
LogUtil.d(this.getClass().getSimpleName(),"heightDifference:"+heightDifference+" usableHeightSansKeyboard:"+usableHeightSansKeyboard+" usableHeightNow"+usableHeightNow);
if (heightDifference > (usableHeightSansKeyboard / 4)) {
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference+stateHeight;
} else {
// 键盘隐藏
frameLayoutParams.height = usableHeightSansKeyboard;
}
mChildOfContent.requestLayout();
usableHeightPrevious = usableHeightNow;
}
}
private int computeUsableHeight() {
Rect r = new Rect();
mChildOfContent.getWindowVisibleDisplayFrame(r);
return (r.bottom - r.top);
}
}
三、图片根据宽度自适应高度
主要是adjustViewBounds和:scaleType两个参数
<ImageView
android:id="@+id/ivHomeApply"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20px"
android:layout_marginBottom="20px"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/pic_entrance_bg" />
网友评论