0

API 21+:

android:background="?android:attr/selectableItemBackgroundBorderless"

API <21:

android:background="?android:attr/selectableItemBackground"

How is it possible?


I know the solution that uses "?attr/API_dependent_theme_reference" like this. This doesn't work for App Widget layout, unfortunately.

Also, I know the solution uses style="..." for the view and multiple style definitions in values and values-v21 folders. But looking for a way to directly assign the background property (especially as Android, unfortunately, don't support assigning multiple styles like CSS: class="style1 style2 etc"!).

Community
  • 1
  • 1
Mir-Ismaili
  • 13,974
  • 8
  • 82
  • 100

1 Answers1

0

You can have two custom drawables

drawable/backround_name.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="?android:attr/selectableItemBackground"
</layer-list>

and

drawable-v21/backround_name.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="?android:attr/selectableItemBackgroundBorderless"
</layer-list>
MaxV
  • 2,601
  • 3
  • 18
  • 25
  • 3
    Thanks for your reply. But unfortunately _"Using theme references in XML drawables" itself "**requires API level 21**"_. See [this unanswered post](http://stackoverflow.com/q/41650820/5318303). If anyone can reply that question, so your answer will be a correct one automatically :) . – Mir-Ismaili Feb 12 '17 at 05:15