I have a separate layout file for Arabic users, that I only want to use for devices that don't support Android's native RTL mirroring (introduced in API level 17). If they are using a device with API 17 or above, I want the default XML file to be used.
How would I accomplish this? I know:
If I put my home.xml
in res/layout/
then it is used as the default layout file.
If I put another home.xml
in res/layout-ar/
then it will be used for arabic speakers
If I put another home.xml
in res/layout-ar-v17/
then it will be used for arabic speakers with v17 or higher.*
*The problem is, I don't want to have another home.xml, I just want the system to use the default and mirror it.
png or background. png image is always the same, but Android selects the version of each resource that best matches the current device, by comparing the device configuration information with the qualifiers in the resource directory name.
The res/values folder is used to store the values for the resources that are used in many Android projects to include features of color, styles, dimensions etc.
Alternative resources are those that you've designed for use with a specific configuration. To specify that a group of resources are for a specific configuration, append an appropriate configuration qualifier to the directory name.
Select layouts , right-click and select New → Folder → Res Folder. This resource folder will represent a “feature category” that you want. You can easily create any type of file/folder in Android Studio.
You could use Layout Aliases. You would end up with two layout files, let's call them home_one.xml and home_two.xml. Then in res/values/layout.xml
and the res/values-ar-v17/layout.xml
you would have
<item name="home" type="layout">@layout/home_one</item>
and in res/values-ar/layout.xml
you would need
<item name="home" type="layout">@layout/home_two</item>
I'd recommend creating two reusable layouts (as described here), one for the default layout and one for Arabic with API level 17+. Then you can define various home.xml
files in appropriate configuration-specific folders so that they <include>
(or <merge>
) the appropriate layout. That way you only need to replication a single <include>
tag instead of an entire layout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With