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.

  • imagebutton gives me error: Missing contentDescription attribute on image
  • EditText: how to enable/disable input?
  • Eclipse android project always lauching in debug
  • Change the action bar settings icon color
  • How to reset Android Studio
  • My App Screen Appears in Browsers
  • 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:

    Getting unknown property &#039;classpath&#039; with Jack compiler for Android
    Android App freezes after implementing Google Firebase
    md5 with Android and PHP
    Android Studio ERROR: Cannot resolve symbol &#039;View&#039;
    Viewpager overflows the screen inside coordinator layout
    AppCompat library 23.2.1 not working with espresso v2.2.2
  • Android get IP-Address of a hotspot providing device
  • Updating to Android SDK Tools R22
  • Gradle build errors while integrating DroidAR in an android studio project
  • How to create Scrollview programmatically?
  • How to check file extension in android
  • Android: How to track if soft-keyboard is openned?
  • 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.