Electronic structure calculations based on density functional theory (DFT) have successfully predicted numerous ground-state properties of a variety of molecules and materials. However, exchange and correlation functionals currently used in the literature, including semilocal and hybrid functionals, are often inaccurate to describe the electronic properties of heterogeneous solids, especially systems composed of building blocks with large dielectric mismatch. Here, we present a dielectric-dependent range-separated hybrid functional, screened-exchange range-separated hybrid (SE-RSH), for the investigation of heterogeneous materials. We define a spatially dependent fraction of exact exchange inspired by the static Coulomb-hole and screened-exchange (COHSEX) approximation used in many-body perturbation theory, and we show that the proposed functional accurately predicts the electronic structure of several nonmetallic interfaces, three- and two-dimensional, pristine, and defective solids and nanoparticles.