I'm wondering if it's possible to specify programatically or in the xml a way to use a
You can change the behavior programmatically, see this answer for that.
So what I would do: if fragment A is resumed, use
getActivity() to get a reference to its parent activity, and then use the command from the question to change the behavior.
Then do the same with fragment B, but use the other parameter when setting the soft input mode behavior.