3

My application supports a minimum of API 8 (platform version 2.2). But borderless buttons require API 11. So when I try to make a button like:

             <button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="displayText"
                style="?android:attr/borderlessButtonStyle" ></button>

Reference: Borderless button subsection in this developer guide

I get an error ?android:attr/borderlessButtonStyle requires API level 11 (current min is 8)

I have the support library android-support-v4.jar in the libs folder of my project. So I removed the android namespace and changed it to style="?attr/borderlessButtonStyle" (suggested in some comment here) and now I get this error: No resource found that matches the given name (at 'style' with value '?attr/borderlessButtonStyle').

I could not either find a "BorderlessButtonStyle" mention, or even that of a "button" in this, or this document?

What should I do? Which support library should I use?


EDIT 1 On suggestion by @NaveenTamatar in the comment:

res/drawable/selector_transparent_button.xml

Problem 1:-

Attribute "exitFadeDuration" is only used in API level 11 and higher (current min is 8)

So I tried this with a slight change:

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="#227EC9" ></item>
    <item android:state_selected="true" android:color="#227EC9"></item>
    <item android:state_enabled="false" android:color="#ADADAD"></item>
    <item android:color="#2E2E2E"/>
</selector>

in a file named selector_transparent_button.xml in res/drawable/ (I created drawable directory myself, those like drawable-hdpi, drawable-ldpi were there but no drawable, a quick web search revealed I could create it, if this matters at all).

Problem 2:-

error: Error: No resource found that matches the given name (at 'drawable' with value '@drawable/button_pressed').

error: Error: No resource found that matches the given name (at 'drawable' with value '@drawable/button_focused').

error: Error: No resource found that matches the given name (at 'drawable' with value '@drawable/button_default').

Community
  • 1
  • 1
Solace
  • 8,612
  • 22
  • 95
  • 183
  • 3
    "But borderless buttons require API 11" -- no, `?android:attr/borderlessButtonStyle` requires API Level 11. That is a specific technique for creating borderless buttons. "Which support library should I use?" -- none of them, as none of them provide a theme backport. Set your own button background that supports various states and does not have a border. You are welcome to trace through the resources for some platform level 11+ to see what background is used by `?android:attr/borderlessButtonStyle`. – CommonsWare Dec 01 '14 at 12:38
  • 1
    ... Does it necessarily have to be a `Button`? Do you know you can use a `TextView` (which is a **clickable** View)? – Phantômaxx Dec 01 '14 at 12:39
  • @DerGolem Yes, but onclick event handling for button is cleaner than that of textview. I will have to do that if this does not work. But why doesn't this work? Secondly I am not sure if `TextView` will allow an image. – Solace Dec 01 '14 at 12:45
  • 3
    res/drawable/selector_transparent_button.xml – Naveen Tamrakar Dec 01 '14 at 12:52
  • @NaveenTamrakar What? – Solace Dec 01 '14 at 12:54
  • create res/drawable/selector_transparent_button.xml this xml file in drawable folder and use it – Naveen Tamrakar Dec 01 '14 at 12:55
  • @CommonsWare " trace through the resources for some platform level 11+..." - I just checked the `styles.xml` in the `values - v14` `res` directory in my project, and all that contains is one `style` tag with nothing: `` Sorry, did I do it wrong? – Solace Dec 01 '14 at 13:01
  • @NaveenTamrakar: A State-List selector is a nice idea. – Phantômaxx Dec 01 '14 at 13:08
  • 1
    @Zarah: `onclick event handling for button is cleaner than that of textview` ... why? you can define an onClick handler in the very same way (I have a **single** onClick handler **I assign in xml** to Buttons, TextViews, ... indifferently). – Phantômaxx Dec 01 '14 at 13:10
  • @NaveenTamrakar `Attribute "exitFadeDuration" is only used in API level 11 and higher (current min is 8)` in the res/drawable/selector_transparent_button.xml file – Solace Dec 01 '14 at 13:35
  • Oh sorry my bad, I meant setting it clickable and all is a bit messy with the `ClickableSpan` and all. – Solace Dec 01 '14 at 13:41

0 Answers0