下面是从 Kotlin 代码函数转换的 java 函数。
@RequiresApi(api = Build.VERSION_CODES.M)
public void setWhiteNavigationBar(@NonNull Dialog dialog) {
Window window = dialog.getWindow();
if (window != null) {
DisplayMetrics metrics = new DisplayMetrics();
window.getWindowManager().getDefaultDisplay().getMetrics(metrics);
GradientDrawable dimDrawable = new GradientDrawable();
GradientDrawable navigationBarDrawable = new GradientDrawable();
navigationBarDrawable.setShape(GradientDrawable.RECTANGLE);
navigationBarDrawable.setColor(Color.WHITE);
val layers = arrayOf<Drawable>(dimDrawable, navigationBarDrawable)
LayerDrawable windowBackground = new LayerDrawable(layers);
windowBackground.setLayerInsetTop(1, metrics.heightPixels);
window.setBackgroundDrawable(windowBackground);
}
}
我在该功能内的以下行遇到了麻烦。我很困惑如何在 Java 的 kotlin 行下面写:
val layers = arrayOf<Drawable>(dimDrawable, navigationBarDrawable)
那么,请任何人指导我们如何在java中编写这一行?
谢谢。