Java tutorial
//package com.java2s; //License from project: Open Source License import android.annotation.SuppressLint; import android.content.Context; import android.os.Build; import android.view.View; public class Main { @SuppressLint("NewApi") @SuppressWarnings("deprecation") public static void setBackground(Context ctx, View view, boolean night, int lightResId, int darkResId) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { view.setBackground(ctx.getResources().getDrawable(night ? darkResId : lightResId, ctx.getTheme())); } else { view.setBackgroundDrawable(ctx.getResources().getDrawable(night ? darkResId : lightResId)); } } }