0

I have added a selector to my layout which should add a white border when the layout is pressed. It works as expected but only works on Android 6.0 and older devices are not getting highlighted. I tried adding android:hardwareAccelerated="true" in the manifest, but that didn't make a difference.

Does anybody know why this doesn't work on older android versions?

Layout that gets highlighted

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:foreground="@drawable/selector">

Selector

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
    android:drawable="@drawable/border_white_rounded" />

border

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/transparent" />

<stroke
    android:width="3dp"
    android:color="@color/color_white" />

<corners android:radius="3dp" />

noev
  • 980
  • 8
  • 26

1 Answers1

0

While the android:foreground has existed since API 1, it was only moved up to the View class in API 23 (Marshmallow, 6.0).

From API 1 until API 23, android:foreground only worked on FrameLayout.

Here is a similar question with some solutions for supporting a foreground in earlier versions of Android: How to set foreground attribute to other non FrameLayout view

Community
  • 1
  • 1
Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120