-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Description
padding can be added to android.R.id.content in the application to solve the problem of third-party libraries not being compatible
private void registerActivityLifecycleCallbacks() {
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
if (activity instanceof PictureSelectorSupporterActivity ||
activity instanceof PictureSelectorTransparentActivity ||
) {
//your idea
NavigationBarUtil.INSTANCE.applyNavigationBarPadding(activity);
}
}
}
object NavigationBarUtil {
val SUPPORT_EDGE_TO_EDGE_VERSION = Build.VERSION_CODES.VANILLA_ICE_CREAM//15+
@JvmField
val isEdgeToEdgeSupported = Build.VERSION.SDK_INT >= SUPPORT_EDGE_TO_EDGE_VERSION
/**
* add padding
*/
fun applyNavigationBarPadding(activity: Activity) {
if (isEdgeToEdgeSupported) {
val rootView = activity.window.decorView.findViewById<View>(android.R.id.content)
if (rootView != null) {
applyNavigationBarInsets(rootView)
}
}
}
/**
* add padding for root view
*/
fun applyNavigationBarInsets(view: View) {
val initialPaddingBottom = view.paddingBottom
ViewCompat.setOnApplyWindowInsetsListener(view) { v: View, insets: WindowInsetsCompat ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(
v.paddingLeft,
v.paddingTop,
v.paddingRight,
initialPaddingBottom + systemBars.bottom
)
insets
}
}
}
TRIM5829, VIkash2601 and shatanikmahanty
Metadata
Metadata
Assignees
Labels
No labels