Reputation: 18863
Is it possible to override an attribute in xml in a tag?
parent.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include
layout="@layout/button"
android:text="HAHAHAH"
/>
</TableLayout>
button.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="some string" />
Is it possible to change "some string" into "HAHAHA"?
Upvotes: 2
Views: 1333
Reputation: 75629
Yes and no :) "Yes", because you can override attributes in XML in general, "no" because in this case only changing android:layout_*
attribues will take effect:
You can also override all the layout parameters (any
android:layout_*
attributes) of the included layout's root view by specifying them in the tag. For example:
<include android:id=”@+id/news_title”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
layout=”@layout/title”/>
However, if you want to override layout attributes using the tag, you must override both android:layout_height and android:layout_width in order for other layout attributes to take effect.
http://developer.android.com/training/improving-layouts/reusing-layouts.html#Include
Upvotes: 5