StatusBar 高度计算 设置background后需要重新设置padding
This commit is contained in:
@@ -27,6 +27,10 @@ import kotlinx.coroutines.channels.Channel
|
||||
import java.util.*
|
||||
import kotlin.math.abs
|
||||
|
||||
fun View.currentPadding() : Array<Int> {
|
||||
return arrayOf(paddingLeft,paddingTop,paddingRight,paddingBottom)
|
||||
}
|
||||
|
||||
val <T: View> T.lifecycleOwner: LifecycleOwner
|
||||
get() = getTag(R.id.view_lifecycle_owner) as? LifecycleOwner ?: object : LifecycleOwner, LifecycleEventObserver {
|
||||
|
||||
|
||||
@@ -57,9 +57,16 @@ public final class BarUtils {
|
||||
* @return the status bar's height
|
||||
*/
|
||||
public static int getStatusBarHeight() {
|
||||
Resources resources = Utils.getApp().getResources();
|
||||
int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
|
||||
return resources.getDimensionPixelSize(resourceId);
|
||||
int result = 0;
|
||||
try {
|
||||
int resourceId = Resources.getSystem().getIdentifier("status_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
result = Resources.getSystem().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
} catch (Resources.NotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -509,38 +509,6 @@ public class CommonUtils {
|
||||
return "";
|
||||
}
|
||||
|
||||
public static int getStatusBarHeight(Context context) {
|
||||
|
||||
if (context == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int statusBarHeight = 0;
|
||||
try {
|
||||
Class c = Class.forName("com.android.internal.R$dimen");
|
||||
Object obj = c.newInstance();
|
||||
Field field = c.getField("status_bar_height");
|
||||
int x = Integer.parseInt(field.get(obj).toString());
|
||||
statusBarHeight = context.getResources().getDimensionPixelSize(x);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
if (statusBarHeight > 0) {
|
||||
return statusBarHeight;
|
||||
}
|
||||
|
||||
try {
|
||||
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
statusBarHeight = context.getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
return statusBarHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某个应用的版本名称
|
||||
*
|
||||
|
||||
@@ -4,20 +4,6 @@ import android.content.Context;
|
||||
|
||||
public class WindowUtils {
|
||||
|
||||
public static int getStatusBarHeight( Context context ) {
|
||||
if ( context == null ) {
|
||||
return 0;
|
||||
} else {
|
||||
int result = 0;
|
||||
int resourceId = context.getResources().getIdentifier( "status_bar_height", "dimen", "android" );
|
||||
if ( resourceId > 0 ) {
|
||||
result = context.getResources().getDimensionPixelSize( resourceId );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据手机的分辨率从 dp 的单位 转成为 px(像素)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user