Дисплей с краем к краюAndroid

Форум для тех, кто программирует под Android
Anonymous
Дисплей с краем к краю

Сообщение Anonymous »

В фрагментируемости я пытаюсь установить вставки, чтобы исправить внешний вид края моего приложения. Для этого я копирую следующий код, взятый от Edge To Edge Display в моей функции Oncreate :

Код: Выделить всё

        ViewCompat.setOnApplyWindowInsetsListener(vue.findViewById(R.id.BoutonFigeDéfige), (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
// Apply the insets as a margin to the view. This solution sets only the
// bottom, left, and right dimensions, but you can apply whichever insets are
// appropriate to your layout. You can also update the view padding if that's
// more appropriate.
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
mlp.leftMargin = insets.left;
mlp.bottomMargin = insets.bottom;
mlp.rightMargin = insets.right;
v.setLayoutParams(mlp);

// Return CONSUMED if you don't want the window insets to keep passing
// down to descendant views.
return WindowInsetsCompat.CONSUMED;
});
Когда я запускаю свое приложение, этот фрагмент кода вызывает ошибку: java.lang.runtimeexception: невозможно запустить Componentinfo {vd63.utilitaires.loupe/vd63.utilitaires.loupe.loupe}: java.lang.lang.nullpointerexceptair. Android.view.view.setonApplyWindowinsetSlistener (android.view.view $ onaptlywindowinsetslistener) 'на ссылке на объект NULL
Как я могу решить эту проблему?

Подробнее здесь: https://stackoverflow.com/questions/797 ... ge-display

Вернуться в «Android»