Burak
Burak

Reputation: 5764

Product Flavors in Android

I have 2 product flavors in an Android project.

I want to use a code base, and I have some code like:

if (BuildConfig.FLAVOR.equals("firstApp")) {
        webButton = (FancyButton) findViewById(R.id.webButton);
        webButton.setBackgroundColor(Util.getColorFromString(""));
        webButton.setIconColor(Util.getColorFromString("#005126"));
}

First App has a layout and it has a button with id webButton.

But in the second app's layout, I don't need the webButton, so I removed it.

But the code above is giving error, because second app doesn't have the button.

What is the way to do that?

Upvotes: 0

Views: 88

Answers (1)

Jibbo
Jibbo

Reputation: 442

You can create a new xml file in values/ that contains the follow resource:

<item type="id" name="webButton"/>

and you are good to go.

Upvotes: 1

Related Questions