Java overwrites XML in Android?

I was wondering what would happen if I write 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); } } 

So far in my manifest I have had this:

 <activity android:name=".ActivityName" android:label="@string/app_name" android:theme="@android:style/Theme.Black.NoTitleBar"> </activity> 

My application started without any problems, but it ran Java code, not what I had in XML. I suppose this is true for all XML editions, but I would like to make sure that if I had Java code similar to XML with few differences, would it use my XML format or Java code?

+4
source share
2 answers

He will always use Java code, as this is the second. However, if you inflate the XML, and you inflate after doing some Java things (into the layout), then XML overrides the code you wrote.

+2
source

Code takes precedence over xml. You can always redefine things from the code you write. As @Cornholio noted, if you manipulate xml-based configurations from java code, it can change what you installed from java code.

However, the Android platform will never overwrite, for example, the xml layout files you created.

+1
source

Source: https://habr.com/ru/post/1483106/


All Articles