You may be able to pull off a Spanish accent when showing off your Antonio Banderas impression, but truly losing your native accent and replacing it with a new one is a lot harder to do. The way you speak now will likely stick with you for life.
According to Smithsonian, our accent develops as early as 6 months old—accents being the pronunciation conventions of a language shaped by factors like region, culture, and class. When a baby is learning the words for nap and dad and play, they're also learning how to pronounce the sounds in those words from the people around them. Newborn brains are wired to recognize and learn languages just from being exposed to them. By the time babies start talking, they know the "right" pronunciations to use for their native language or languages.
As you get older, your innate understanding of foreign accents and languages gets weaker. If you're an English speaker raised in Boston, you may think that the way someone from Dallas speaks English sounds "wrong" without being able to articulate what it is that makes them sound different. This is why pulling off a convincing foreign accent can be so difficult, even if you've heard it many times before.
Around age 18, your ability to learn a second language takes a steep nosedive. The same may be true with your ability to speak in a new accent. If you immerse yourself in a foreign environment for long enough, you may pick up some ticks of the local accent, but totally adopting a non-native accent without making a conscious effort to maintain it is unlikely as an adult.
There is one exception to this rule, and that's Foreign Accent Syndrome. Following a head injury or stroke, some people have reported suddenly speaking in accents they didn't grow up using. The syndrome is incredibly rare, with only 100 people around the world having been diagnosed with it, and medical experts aren't sure why brain injuries cause it. But while patients may be pronouncing their words differently, they aren't exactly using foreign accents in the way most people think of them; the culprit may be subtle changes to muscle movements in the jaw, tongue, lips, and larynx that change the way patients pronounce certain vowels.