Physics-informed neural networks (PINNs) are widely used in the field of solid mechanics. Currently, PINNs are mainly used to solve problems involving single homogeneous materials. However, they have limited ability to handle the discontinuities that arise from multi-material, and they lack the capability to rigorously express complex material contact models. We propose a method for solving multi-material problems in solid mechanics using physics-informed neural networks. Inspired by domain decomposition technology, the calculation domain is divided according to the geometric distribution of materials, with different subnetworks applied to represent field variables. This study explains how the invariant momentum balance, kinematic relations, and different constitutive relations controlled by the material properties are incorporated into the subnetworks, and use additional regular terms to describe the contact relations between materials. Various test cases ranging from two-dimensional plane strain problems to three-dimensional stretching problems are solved using the proposed method. We introduce the concept of parameter sharing in multi-task learning (MTL) and incorporate it in the proposed method, which yields additional degrees of freedom in choosing the sharing structure and sharing mode. Compared with common physics-informed neural network algorithms, which are based on fully independent parameters, we develop a network structure with partial sharing structure and all-sharing mode that achieves higher accuracy when solving the example problems.