Borderless Button on Pre-Lollipop with Support Library

I am making borderless flat button using support library (23.0.1). It works normal on Lollipop. However on pre-Lollipop when I press button Its color changes to colorButtonNormal color like it’s a normal button.

I don’t think so it’s a normal behaviour and focused color should be grey like on Lollipop.

  • Mockito mocks run actual Android code in Lollipop or greater
  • RecyclerView does not scroll as expected
  • Android sort listview alphabetically
  • Update Eclipse with Android development tools v. 23
  • How to deserialise a subclass in Firebase using getValue(Subclass.class)
  • Android 5.1.1 default camera return empty intent in onActivityResult after capturing image
  • Here’s the screenshot from Lollipop and Pre-lollipop.

    First normal behaviour on Lollipop:
    Borderless button in normal state and focused state on Lollipop

    enter image description here

    Not normal behaviour on Pre-Lollipop (Desire color is gray like above but it’s not):
    Borderless button in normal state and focused state on Pre-lollipop
    enter image description here

    Theme

    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    //other stuff 
            <item name="colorButtonNormal">@color/orangeColor</item>
            <item name="buttonBarButtonStyle">@style/BorderlessButtonStyle</item>
    </style>
    
    <style name="BorderlessButtonStyle" parent="Widget.AppCompat.Button.Borderless">
            <item name="android:textColor">@color/blueTextColor</item>
    </style>
    

    And now button in layout:

    <Button
                android:id="@+id/btnForgotPassword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/forgot_your_password"
                style="?attr/buttonBarButtonStyle"
                />
    

    Any way to get it write using AppCompat Theme and styles without of making separate Drawables.

    Related posts:

    Ideas of Source of QualcommCameraHardware native_get_picture: MSM_CAM_IOCTL_GET_PICTURE Connection t...
    Get the displayed size of an image inside an ImageView
    SharedPreferences Clear/Save
    Convert SQLite to JSON
    String Encoding problem in Webview
    Set target mail address in Firebase Invites
  • Google Play Services 9.2.0 missing classes
  • Does react native compile JavaScript into Java for Android?
  • Android CheckBoxPreference: how to disable and enable other preferences on preference change
  • Why do child views inherit the alpha value from parent layout
  • Align 2 texts, 1 normal, 1 opposite
  • View.inflate vs LayoutInflater
  • 4 Solutions collect form web for “Borderless Button on Pre-Lollipop with Support Library”

    Borderless Button works on both Post and Pre Lollipop version with Support Library but there’s a small difference between their onPressed color.

    Pre-Lollipop: By default onPressed color is same as default Button color set using colorButtonNormal.

    Lollipop: By default onPressed color is light grey, which is ideal.

    You can make a Borderless Button like this:

    <Button  
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Name"
        style="@style/Widget.AppCompat.Button.Borderless"/>
    

    Now If you want to have the same onPressed color on all versions then you can set colorControlHighlight in a new theme and set that theme on Button.

    <Button  
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Name"
            android:theme="@style/BorderlessButton"
            style="@style/Widget.AppCompat.Button.Borderless"/>
    

    And theme in your style:

    <style name="BorderlessButton" parent="Theme.AppCompat.Light">
          <item name="colorControlHighlight">YOUR COLOR</item>
    </style>
    

    Updated: You can use android:theme attribute for a View since Android 5.0 Lollipop and AppCompat v22.1.0 (and higher).

    why do you worry with some things just go with this and be free

    <Button
       android:id="@+id/btnForgotPassword"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="@string/forgot_your_password"
       android:background="@drawable/abc_btn_borderless_material"
    />
    

    and now careless about api stuff

    Adding style="?attr/borderlessButtonStyle" to the Button worked fine for me.

    You are using the android implemented style of “buttonBarButtonStyle” since you are calling it via ?atr – use style="@style/BorderlessButtonStyle instead.

    Edit: Leave your xml as it is, but you can change it to your wanted behaviour like this:

    AppCompatButton button = (AppCompatButton) findViewById(R.id.btnForgotPassword);
    
    ColorStateList colorStateList = new ColorStateList(new int[][] {{0}}, new int[] {0xFF969696});  
        //969696 is your wanted grey color, just change it
    button.setSupportBackgroundTintList(colorStateList);
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.