I have a layout where just one part of it is api level dependent (it uses vectors) and I need to handle it differently for api-19. I changed the layout to handle those using app:srcCompat:"@drawable/left_arrow_vector"
which works to make 19 not crash, but when I test it on other api levels, it still shows the same layout as api-19 (There is a sizing problem which makes it easy to see. I'll fix that when I get this part figured out).
res/layout-v19:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@id/calTitleBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<ImageView
android:id="@id/prevMonth"
app:srcCompat="@drawable/left_arrow_vector"
android:contentDescription="@string/prev_month"
android:layout_height="24dp"
android:layout_width="24dp" />
<TextView
android:id="@id/calMonth"
style="@style/CalendarTitle"
android:layout_toStartOf="@id/nextMonth"
android:layout_toEndOf="@id/prevMonth"
tools:text="JANUARY 2019" />
<ImageView
android:id="@id/nextMonth"
android:layout_alignParentRight="true"
app:srcCompat="@drawable/right_arrow_vector"
android:contentDescription="@string/next_month"
android:layout_height="24dp"
android:layout_width="24dp" />
</RelativeLayout>
res/layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@id/calTitleBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<ImageButton
android:id="@id/prevMonth"
style="@style/CalendarLeftArrowButton"
android:contentDescription="@string/prev_month" />
<TextView
android:id="@id/calMonth"
style="@style/CalendarTitle"
android:layout_toStartOf="@id/nextMonth"
android:layout_toEndOf="@id/prevMonth"
tools:text="JANUARY 2019" />
<ImageButton
android:id="@id/nextMonth"
style="@style/CalendarRightArrowButton"
android:contentDescription="@string/next_month" />
</RelativeLayout>
relevant part of styles.xml:
<style name="CalendarArrowButtons">
<item name="android:layout_width">44dp</item>
<item name="android:layout_height">44dp</item>
</style>
<style name="CalendarLeftArrowButton" parent="CalendarArrowButtons">
<item name="android:layout_alignParentLeft">true</item>
<item name="android:background">@drawable/left_arrow_vector</item>
</style>
<style name="CalendarRightArrowButton" parent="CalendarArrowButtons">
<item name="android:layout_alignParentRight">true</item>
<item name="android:background">@drawable/right_arrow_vector</item>
</style>
When I remove the include and just use either directly, it displays right (well, the normal layout crashes on 19, but that's to be expected) on the respective versions.