The main problem of eating/drinking kosher food in non-kosher food is marit ayin, the appearance of doing something wrong, which would either reflect badly on the person or suggest to others the restaurant is kosher.
Some write that drinking a product known to be kosher (e.g., Coke in bottle/can) doesn't create marit ayin because it doesn't suggest the place is kosher. On the other side, coming out of a restaurant with a bag of something (even if it is only a kosher drink) might create this perception.
So the answer is likely to be context-dependent. To take your example, everyone knows that McDonald's is not kosher, so no one will start eating there after seeing a Jew come out of the drive-in. On the other side, people might start to believe this Jew doesn't eat kosher.
Answering a similar question din.org writes
According to Iggros Moshe, maris ayin applies when “Someone thinks
that I violated something, or he thinks that I inappropriately ate
something non-kosher”.
However, this applies to eating in a non-kosher restaurant, but not
necessarily to buying a drink over the counter. It is normal for
somebody to buy a drink over the counter without eating anything in
the restaurant, and therefore it appears that this will not constitute
maris ayin.
Yet, it is better to avoid entering a non-kosher restaurant
altogether, and if possible one should buy the drink at a drinks
machine. Where this is not possible, one may enter to buy the drink,
but not sit down at a table to drink it.
R Ari Wasserman has an entire chapter on the topic in his excellent book Making It Work. He quotes R Asher Weiss permitting a scenario similar to the one you describe where the action is commonly known to be permitted (i.e., buying a kosher drink from McDonald's).
Ultimately these questions depend on the specifics of the situation, both in terms of the restaurant, the food consumed, the possibility someone will see the act, and maybe even the individual involved. Your local rabbi is best placed to advise on the right behavior.