Pallas
Pallas

Reputation: 1579

Programmatically Changing a XML file?

I have a XML file that I set up to tell the app what image to use as the splash screen. However, I have multiple images that can be used depending on the screen size. I have the following code to determine the screen size:

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();
int height = display.getHeight();

Note: I'm using getWidth and getHeight because my app is using API 7. I do know that they were deprecated later on.

Anyways, here is what I have in my XML file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Splash" parent="android:Theme">
    <item name="android:windowBackground">@drawable/splash_screen</item>
    <item name="android:windowNoTitle">true</item>
</style>
</resources>

Basically, what I want to be able to do is be able to programmatically change splash_screen to whatever the name of my file is depending on the screen size. Any ideas how I can change the XML file from my code?

Thanks in advance for any help given.

Upvotes: 1

Views: 3592

Answers (2)

jtt
jtt

Reputation: 13541

If this is in your resources, you CANNOT modify your resources at run time. Only thing you can do is programatically build your layout/styles.

Upvotes: -1

Diego Torres Milano
Diego Torres Milano

Reputation: 69198

You don't have to do it manually. Resource qualifiers do this for you, so you can always refer to a resource by a single name. Check the information and examples available at http://developer.android.com/guide/practices/screens_support.html.

Upvotes: 3

Related Questions