Reputation: 75
I was wondering what would happen if I wrote one code in XML and another in Java.
I had this code in my program:
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class ActivityName extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
While in my Manifest I had this:
<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar">
</activity>
My application started with no issues but ran the Java code and not what I had in XML. I assume this is true for all XML edits but wanted to make sure, if I had a Java code that is similar to XML with a bit of differences, would it use my XML format or Java code?
Upvotes: 4
Views: 107
Reputation: 985
It'll always use the Java code, since that's run second. If you're inflating from XML, though, and you inflate after doing some Java stuff (to the layout), then the XML overrides the code you wrote.
Upvotes: 2
Reputation: 30548
The code takes precedence over xml. You can always over-define things from the code you write. As @Cornholio pointed out if you manipulate xml-based configurations from java code it can modify things you have set from java code.
The Android framework however will never overwrite for example the xml layout files you created.
Upvotes: 1