Override layout xml from android framework Override layout xml from android framework android android

Override layout xml from android framework


I know this is an old question but I also wanted to override a library layout with my own, here's how I did it.

The layout in question was called design_bottom_navigation_item

In refs.xml I added the following:

<resources xmlns:tools="http://schemas.android.com/tools">    <item name="design_bottom_navigation_item" type="layout" tools:override="true">@layout/bottom_navigation_item</item></resources>

There are 4 parts to this which I'll explain.

  • Name: This is the name of the layout you want to override
  • Type: The type of resource you are trying to override, in this case a layout.
  • tools:override: This is how you tell Android Studio to override the library layout with your own.
  • Value: This is where you specify what resource you want to use instead.

You can do this with any resource type this way.


What is that you're trying to do?

If the idea to only replace how the menu-item will look like, you can try the following:

  1. Create a custom MyMenuAdapter extends MenuAdapter
  2. Override the getView method to return the view from your adapter.


You are trying to customise your sdk on the application itself, at runtime.

That's just not how it works.

If you use an SDK on your project(on any technologies), and you need to modify some behavior, you will tweak this SDK and after that, compile your project with this news customized version.
Trying to modify it at runtime is not a good idea.
You will face multiple issues (retro compatibility, security trigger, TREBLE incompatibility , dependency issue, etc)

You have 4 possibilities to do what you want:

  1. Make your own android rom where you will apply your modification
  2. Copy the resources you need to modify on a fake xmlObject with the tag, after the onPostCreate of your application, you will be able to modify the when inflation. You can generalize this behavior and it will simulate an sdk overlay.
  3. Make your own sdk :)
  4. Multi-level reflection, but, no way you succeed with a stable version

Of course, none of this solutions is applicable for a public app.