What current does the solenoid draw?
If the battery is lead acid it is useable over a 10-14V range typically, so if you definitely need 12 to 9V you would have to use a switch mode power supply. If the solenoid will work satisfactorily at lower voltages, then none of the above will be an issue, and the simplest circuit is variable resistor, but since you have not specified a solenoid current, I have no way of knowing what power rating would be needed, it may well be impractical. Next option is an emitter follower. The output voltage can be adjusted with a variable resistor. You have to be aware of power dissipation in the pass transistor (again, you need to specify the solenoid current), and put a diode across the solenoid to clip the high reverse voltage flyback if the power is turned off, damaging your control circuit.
Now there are a number of problems with this simple circuit, which mean that additional parts are needed to overcome them. With a fixed load resistance, and no need for high precision (temperature stability etc) you would probably get away with it if the current is low enough.
Article here
https://learnabout-electronics.org/PSU/psu22.php covers some of the basics.
Quite a bit to consider for such a simple request!
There are any number of integrated circuit solutions available as well, including monolithic if the current/power is low enough.
Cheers,
Richard