Custom AppCompatButton getting wrong colors on Android 5 (Api 21)











up vote
0
down vote

favorite












So I've implemented a custom button for our app, the implementation works perfect on Android 6 and up but I run into an issue on Android 5, where the background color doesn't get applied until I press the button once. Then it looks as it should.




  • Buttons not correct

  • Buttons correct


The implementation looks like this:



class MpButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.style.ButtonStyle) : AppCompatButton(context, attrs, defStyleAttr) {

private val toScale = 0.9f
private val fromScale = 1f

init {
var style = 0
var allCaps = false

attrs?.let {
val a = context.obtainStyledAttributes(it, R.styleable.MpButton)
style = a.getInt(R.styleable.MpButton_MpButtonColor, 0)
allCaps = a.getBoolean(R.styleable.MpButton_MpButtonAllcaps, false)
a.recycle()
}

when (style) {
WHITE -> {
this.setBackgroundResource(R.drawable.mp_button_white)
this.setTextColor(ContextCompat.getColor(context, R.color.white))
}
RED -> {
this.setBackgroundResource(R.drawable.mp_button_red)
this.setTextColor(ContextCompat.getColor(context, R.color.white))
}
BLACK -> {
this.setBackgroundResource(R.drawable.mp_button_black)
this.setTextColor(ContextCompat.getColor(context, R.color.mp_black))
}
BLUE -> {
this.setBackgroundResource(R.drawable.mp_button_blue)
this.setTextColor(ContextCompat.getColor(context, R.color.white))
}
YELLOW -> {
this.setBackgroundResource(R.drawable.mp_button_yellow)
this.setTextColor(ContextCompat.getColor(context, R.color.white))
}
else -> {
this.setBackgroundResource(R.drawable.mp_button_green)
this.setTextColor(ContextCompat.getColor(context, R.color.white))
}
}

this.gravity = Gravity.CENTER
val padding = Utils.convertDpToPixel(context, 5)
this.setPadding(padding, padding, padding, padding)
this.isAllCaps = allCaps
}

override fun dispatchTouchEvent(event: MotionEvent): Boolean {
when(event.action) {
MotionEvent.ACTION_DOWN -> {
this.animate().scaleX(toScale).scaleY(toScale).setDuration(100).start()
}
MotionEvent.ACTION_UP -> {
this.animate().scaleX(fromScale).scaleY(fromScale).setDuration(100).start()
}
}
return super.dispatchTouchEvent(event)
}

companion object {
const val WHITE = 1
const val RED = 2
const val BLACK = 3
const val BLUE = 4
const val YELLOW = 5
}
}


For info Ill also add the XML for one of the colors:



<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/mp_black">
<item>
<selector
android:exitFadeDuration="@android:integer/config_mediumAnimTime"
android:enterFadeDuration="@android:integer/config_shortAnimTime">
<item android:state_enabled="true" android:state_pressed="false">
<shape android:shape="rectangle">
<corners android:radius="30dp"/>
<solid android:color="@color/jungle_green" />
</shape>
</item>
<item android:state_enabled="true" android:state_pressed="true">
<shape android:shape="rectangle">
<corners android:radius="30dp"/>
<solid android:color="@color/forest" />
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<corners android:radius="30dp"/>
<solid android:color="@color/mp_gray_5" />
</shape>
</item>
</selector>
</item>
</ripple>


As a last ill copy the part of the XML of the view aswell to give as much info as possible:



<se.motesplatsen.app.ui.controls.MpButton
android:id="@+id/btnStartLogin"
android:layout_width="220dp"
android:layout_height="44dp"
android:text="@string/DEFAULT_LOGIN"
android:layout_marginBottom="10dp"
android:layout_marginTop="20dp"
app:MpButtonAllcaps="true"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnStartBecomeMember"/>

<se.motesplatsen.app.ui.controls.MpButton
android:id="@+id/btnStartBecomeMember"
android:layout_width="220dp"
android:layout_height="44dp"
android:layout_marginTop="25dp"
android:text="@string/BECOME_MEMBER_BUTTON"
app:MpButtonColor="1"
app:MpButtonAllcaps="true"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintTop_toBottomOf="@id/tvStartDesc"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@id/btnStartLogin"/>









share|improve this question




























    up vote
    0
    down vote

    favorite












    So I've implemented a custom button for our app, the implementation works perfect on Android 6 and up but I run into an issue on Android 5, where the background color doesn't get applied until I press the button once. Then it looks as it should.




    • Buttons not correct

    • Buttons correct


    The implementation looks like this:



    class MpButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.style.ButtonStyle) : AppCompatButton(context, attrs, defStyleAttr) {

    private val toScale = 0.9f
    private val fromScale = 1f

    init {
    var style = 0
    var allCaps = false

    attrs?.let {
    val a = context.obtainStyledAttributes(it, R.styleable.MpButton)
    style = a.getInt(R.styleable.MpButton_MpButtonColor, 0)
    allCaps = a.getBoolean(R.styleable.MpButton_MpButtonAllcaps, false)
    a.recycle()
    }

    when (style) {
    WHITE -> {
    this.setBackgroundResource(R.drawable.mp_button_white)
    this.setTextColor(ContextCompat.getColor(context, R.color.white))
    }
    RED -> {
    this.setBackgroundResource(R.drawable.mp_button_red)
    this.setTextColor(ContextCompat.getColor(context, R.color.white))
    }
    BLACK -> {
    this.setBackgroundResource(R.drawable.mp_button_black)
    this.setTextColor(ContextCompat.getColor(context, R.color.mp_black))
    }
    BLUE -> {
    this.setBackgroundResource(R.drawable.mp_button_blue)
    this.setTextColor(ContextCompat.getColor(context, R.color.white))
    }
    YELLOW -> {
    this.setBackgroundResource(R.drawable.mp_button_yellow)
    this.setTextColor(ContextCompat.getColor(context, R.color.white))
    }
    else -> {
    this.setBackgroundResource(R.drawable.mp_button_green)
    this.setTextColor(ContextCompat.getColor(context, R.color.white))
    }
    }

    this.gravity = Gravity.CENTER
    val padding = Utils.convertDpToPixel(context, 5)
    this.setPadding(padding, padding, padding, padding)
    this.isAllCaps = allCaps
    }

    override fun dispatchTouchEvent(event: MotionEvent): Boolean {
    when(event.action) {
    MotionEvent.ACTION_DOWN -> {
    this.animate().scaleX(toScale).scaleY(toScale).setDuration(100).start()
    }
    MotionEvent.ACTION_UP -> {
    this.animate().scaleX(fromScale).scaleY(fromScale).setDuration(100).start()
    }
    }
    return super.dispatchTouchEvent(event)
    }

    companion object {
    const val WHITE = 1
    const val RED = 2
    const val BLACK = 3
    const val BLUE = 4
    const val YELLOW = 5
    }
    }


    For info Ill also add the XML for one of the colors:



    <?xml version="1.0" encoding="utf-8"?>
    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@color/mp_black">
    <item>
    <selector
    android:exitFadeDuration="@android:integer/config_mediumAnimTime"
    android:enterFadeDuration="@android:integer/config_shortAnimTime">
    <item android:state_enabled="true" android:state_pressed="false">
    <shape android:shape="rectangle">
    <corners android:radius="30dp"/>
    <solid android:color="@color/jungle_green" />
    </shape>
    </item>
    <item android:state_enabled="true" android:state_pressed="true">
    <shape android:shape="rectangle">
    <corners android:radius="30dp"/>
    <solid android:color="@color/forest" />
    </shape>
    </item>
    <item android:state_enabled="false">
    <shape android:shape="rectangle">
    <corners android:radius="30dp"/>
    <solid android:color="@color/mp_gray_5" />
    </shape>
    </item>
    </selector>
    </item>
    </ripple>


    As a last ill copy the part of the XML of the view aswell to give as much info as possible:



    <se.motesplatsen.app.ui.controls.MpButton
    android:id="@+id/btnStartLogin"
    android:layout_width="220dp"
    android:layout_height="44dp"
    android:text="@string/DEFAULT_LOGIN"
    android:layout_marginBottom="10dp"
    android:layout_marginTop="20dp"
    app:MpButtonAllcaps="true"
    app:layout_constraintVertical_chainStyle="packed"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/btnStartBecomeMember"/>

    <se.motesplatsen.app.ui.controls.MpButton
    android:id="@+id/btnStartBecomeMember"
    android:layout_width="220dp"
    android:layout_height="44dp"
    android:layout_marginTop="25dp"
    android:text="@string/BECOME_MEMBER_BUTTON"
    app:MpButtonColor="1"
    app:MpButtonAllcaps="true"
    app:layout_constraintVertical_chainStyle="packed"
    app:layout_constraintTop_toBottomOf="@id/tvStartDesc"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintBottom_toTopOf="@id/btnStartLogin"/>









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      So I've implemented a custom button for our app, the implementation works perfect on Android 6 and up but I run into an issue on Android 5, where the background color doesn't get applied until I press the button once. Then it looks as it should.




      • Buttons not correct

      • Buttons correct


      The implementation looks like this:



      class MpButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.style.ButtonStyle) : AppCompatButton(context, attrs, defStyleAttr) {

      private val toScale = 0.9f
      private val fromScale = 1f

      init {
      var style = 0
      var allCaps = false

      attrs?.let {
      val a = context.obtainStyledAttributes(it, R.styleable.MpButton)
      style = a.getInt(R.styleable.MpButton_MpButtonColor, 0)
      allCaps = a.getBoolean(R.styleable.MpButton_MpButtonAllcaps, false)
      a.recycle()
      }

      when (style) {
      WHITE -> {
      this.setBackgroundResource(R.drawable.mp_button_white)
      this.setTextColor(ContextCompat.getColor(context, R.color.white))
      }
      RED -> {
      this.setBackgroundResource(R.drawable.mp_button_red)
      this.setTextColor(ContextCompat.getColor(context, R.color.white))
      }
      BLACK -> {
      this.setBackgroundResource(R.drawable.mp_button_black)
      this.setTextColor(ContextCompat.getColor(context, R.color.mp_black))
      }
      BLUE -> {
      this.setBackgroundResource(R.drawable.mp_button_blue)
      this.setTextColor(ContextCompat.getColor(context, R.color.white))
      }
      YELLOW -> {
      this.setBackgroundResource(R.drawable.mp_button_yellow)
      this.setTextColor(ContextCompat.getColor(context, R.color.white))
      }
      else -> {
      this.setBackgroundResource(R.drawable.mp_button_green)
      this.setTextColor(ContextCompat.getColor(context, R.color.white))
      }
      }

      this.gravity = Gravity.CENTER
      val padding = Utils.convertDpToPixel(context, 5)
      this.setPadding(padding, padding, padding, padding)
      this.isAllCaps = allCaps
      }

      override fun dispatchTouchEvent(event: MotionEvent): Boolean {
      when(event.action) {
      MotionEvent.ACTION_DOWN -> {
      this.animate().scaleX(toScale).scaleY(toScale).setDuration(100).start()
      }
      MotionEvent.ACTION_UP -> {
      this.animate().scaleX(fromScale).scaleY(fromScale).setDuration(100).start()
      }
      }
      return super.dispatchTouchEvent(event)
      }

      companion object {
      const val WHITE = 1
      const val RED = 2
      const val BLACK = 3
      const val BLUE = 4
      const val YELLOW = 5
      }
      }


      For info Ill also add the XML for one of the colors:



      <?xml version="1.0" encoding="utf-8"?>
      <ripple xmlns:android="http://schemas.android.com/apk/res/android"
      android:color="@color/mp_black">
      <item>
      <selector
      android:exitFadeDuration="@android:integer/config_mediumAnimTime"
      android:enterFadeDuration="@android:integer/config_shortAnimTime">
      <item android:state_enabled="true" android:state_pressed="false">
      <shape android:shape="rectangle">
      <corners android:radius="30dp"/>
      <solid android:color="@color/jungle_green" />
      </shape>
      </item>
      <item android:state_enabled="true" android:state_pressed="true">
      <shape android:shape="rectangle">
      <corners android:radius="30dp"/>
      <solid android:color="@color/forest" />
      </shape>
      </item>
      <item android:state_enabled="false">
      <shape android:shape="rectangle">
      <corners android:radius="30dp"/>
      <solid android:color="@color/mp_gray_5" />
      </shape>
      </item>
      </selector>
      </item>
      </ripple>


      As a last ill copy the part of the XML of the view aswell to give as much info as possible:



      <se.motesplatsen.app.ui.controls.MpButton
      android:id="@+id/btnStartLogin"
      android:layout_width="220dp"
      android:layout_height="44dp"
      android:text="@string/DEFAULT_LOGIN"
      android:layout_marginBottom="10dp"
      android:layout_marginTop="20dp"
      app:MpButtonAllcaps="true"
      app:layout_constraintVertical_chainStyle="packed"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toBottomOf="@id/btnStartBecomeMember"/>

      <se.motesplatsen.app.ui.controls.MpButton
      android:id="@+id/btnStartBecomeMember"
      android:layout_width="220dp"
      android:layout_height="44dp"
      android:layout_marginTop="25dp"
      android:text="@string/BECOME_MEMBER_BUTTON"
      app:MpButtonColor="1"
      app:MpButtonAllcaps="true"
      app:layout_constraintVertical_chainStyle="packed"
      app:layout_constraintTop_toBottomOf="@id/tvStartDesc"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintBottom_toTopOf="@id/btnStartLogin"/>









      share|improve this question















      So I've implemented a custom button for our app, the implementation works perfect on Android 6 and up but I run into an issue on Android 5, where the background color doesn't get applied until I press the button once. Then it looks as it should.




      • Buttons not correct

      • Buttons correct


      The implementation looks like this:



      class MpButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.style.ButtonStyle) : AppCompatButton(context, attrs, defStyleAttr) {

      private val toScale = 0.9f
      private val fromScale = 1f

      init {
      var style = 0
      var allCaps = false

      attrs?.let {
      val a = context.obtainStyledAttributes(it, R.styleable.MpButton)
      style = a.getInt(R.styleable.MpButton_MpButtonColor, 0)
      allCaps = a.getBoolean(R.styleable.MpButton_MpButtonAllcaps, false)
      a.recycle()
      }

      when (style) {
      WHITE -> {
      this.setBackgroundResource(R.drawable.mp_button_white)
      this.setTextColor(ContextCompat.getColor(context, R.color.white))
      }
      RED -> {
      this.setBackgroundResource(R.drawable.mp_button_red)
      this.setTextColor(ContextCompat.getColor(context, R.color.white))
      }
      BLACK -> {
      this.setBackgroundResource(R.drawable.mp_button_black)
      this.setTextColor(ContextCompat.getColor(context, R.color.mp_black))
      }
      BLUE -> {
      this.setBackgroundResource(R.drawable.mp_button_blue)
      this.setTextColor(ContextCompat.getColor(context, R.color.white))
      }
      YELLOW -> {
      this.setBackgroundResource(R.drawable.mp_button_yellow)
      this.setTextColor(ContextCompat.getColor(context, R.color.white))
      }
      else -> {
      this.setBackgroundResource(R.drawable.mp_button_green)
      this.setTextColor(ContextCompat.getColor(context, R.color.white))
      }
      }

      this.gravity = Gravity.CENTER
      val padding = Utils.convertDpToPixel(context, 5)
      this.setPadding(padding, padding, padding, padding)
      this.isAllCaps = allCaps
      }

      override fun dispatchTouchEvent(event: MotionEvent): Boolean {
      when(event.action) {
      MotionEvent.ACTION_DOWN -> {
      this.animate().scaleX(toScale).scaleY(toScale).setDuration(100).start()
      }
      MotionEvent.ACTION_UP -> {
      this.animate().scaleX(fromScale).scaleY(fromScale).setDuration(100).start()
      }
      }
      return super.dispatchTouchEvent(event)
      }

      companion object {
      const val WHITE = 1
      const val RED = 2
      const val BLACK = 3
      const val BLUE = 4
      const val YELLOW = 5
      }
      }


      For info Ill also add the XML for one of the colors:



      <?xml version="1.0" encoding="utf-8"?>
      <ripple xmlns:android="http://schemas.android.com/apk/res/android"
      android:color="@color/mp_black">
      <item>
      <selector
      android:exitFadeDuration="@android:integer/config_mediumAnimTime"
      android:enterFadeDuration="@android:integer/config_shortAnimTime">
      <item android:state_enabled="true" android:state_pressed="false">
      <shape android:shape="rectangle">
      <corners android:radius="30dp"/>
      <solid android:color="@color/jungle_green" />
      </shape>
      </item>
      <item android:state_enabled="true" android:state_pressed="true">
      <shape android:shape="rectangle">
      <corners android:radius="30dp"/>
      <solid android:color="@color/forest" />
      </shape>
      </item>
      <item android:state_enabled="false">
      <shape android:shape="rectangle">
      <corners android:radius="30dp"/>
      <solid android:color="@color/mp_gray_5" />
      </shape>
      </item>
      </selector>
      </item>
      </ripple>


      As a last ill copy the part of the XML of the view aswell to give as much info as possible:



      <se.motesplatsen.app.ui.controls.MpButton
      android:id="@+id/btnStartLogin"
      android:layout_width="220dp"
      android:layout_height="44dp"
      android:text="@string/DEFAULT_LOGIN"
      android:layout_marginBottom="10dp"
      android:layout_marginTop="20dp"
      app:MpButtonAllcaps="true"
      app:layout_constraintVertical_chainStyle="packed"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toBottomOf="@id/btnStartBecomeMember"/>

      <se.motesplatsen.app.ui.controls.MpButton
      android:id="@+id/btnStartBecomeMember"
      android:layout_width="220dp"
      android:layout_height="44dp"
      android:layout_marginTop="25dp"
      android:text="@string/BECOME_MEMBER_BUTTON"
      app:MpButtonColor="1"
      app:MpButtonAllcaps="true"
      app:layout_constraintVertical_chainStyle="packed"
      app:layout_constraintTop_toBottomOf="@id/tvStartDesc"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintBottom_toTopOf="@id/btnStartLogin"/>






      android xml android-layout kotlin






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 10:16









      André Sousa

      1,1461818




      1,1461818










      asked Nov 12 at 8:55









      Oskar Gustavsson

      34




      34
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
          <corners
          android:radius="5dp"
          />
          <solid
          android:color="@color/Transparent"
          />




          just use this as background you are using on pressed state in your file






          share|improve this answer





















          • Thanks for your responses, however im not sure what you mean, my issue is not that its not correct in the XML its that Android 5 doesnt render it correctly until I press it the first time. If you look at the correct picture there are 2 buttons and both of thoose are correct, and they look like that in all android versions above 5. The left ones are from Android 5 where the xml doesnt seem to apply until I press the button one time...
            – Oskar Gustavsson
            Nov 13 at 12:26


















          up vote
          0
          down vote













          <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
          <item>
          <shape >
          <solid android:color="@android:color/white"/>
          <size android:height="1dp"/>
          </shape>
          </item>
          <item android:bottom="2dip" android:top="2dip" android:left="2dip" android:right="2dip">
          <shape>
          <solid android:color="@android:color/Transparent"/>
          </shape>
          </item>




          this is exactly look like your correct button






          share|improve this answer





















          • See comment above, Im pretty sure its not an XML issue, but something with Android 5
            – Oskar Gustavsson
            Nov 13 at 12:26











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258682%2fcustom-appcompatbutton-getting-wrong-colors-on-android-5-api-21%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
          <corners
          android:radius="5dp"
          />
          <solid
          android:color="@color/Transparent"
          />




          just use this as background you are using on pressed state in your file






          share|improve this answer





















          • Thanks for your responses, however im not sure what you mean, my issue is not that its not correct in the XML its that Android 5 doesnt render it correctly until I press it the first time. If you look at the correct picture there are 2 buttons and both of thoose are correct, and they look like that in all android versions above 5. The left ones are from Android 5 where the xml doesnt seem to apply until I press the button one time...
            – Oskar Gustavsson
            Nov 13 at 12:26















          up vote
          0
          down vote













          <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
          <corners
          android:radius="5dp"
          />
          <solid
          android:color="@color/Transparent"
          />




          just use this as background you are using on pressed state in your file






          share|improve this answer





















          • Thanks for your responses, however im not sure what you mean, my issue is not that its not correct in the XML its that Android 5 doesnt render it correctly until I press it the first time. If you look at the correct picture there are 2 buttons and both of thoose are correct, and they look like that in all android versions above 5. The left ones are from Android 5 where the xml doesnt seem to apply until I press the button one time...
            – Oskar Gustavsson
            Nov 13 at 12:26













          up vote
          0
          down vote










          up vote
          0
          down vote









          <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
          <corners
          android:radius="5dp"
          />
          <solid
          android:color="@color/Transparent"
          />




          just use this as background you are using on pressed state in your file






          share|improve this answer












          <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
          <corners
          android:radius="5dp"
          />
          <solid
          android:color="@color/Transparent"
          />




          just use this as background you are using on pressed state in your file







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 10:46









          Muhammad Waqas

          32110




          32110












          • Thanks for your responses, however im not sure what you mean, my issue is not that its not correct in the XML its that Android 5 doesnt render it correctly until I press it the first time. If you look at the correct picture there are 2 buttons and both of thoose are correct, and they look like that in all android versions above 5. The left ones are from Android 5 where the xml doesnt seem to apply until I press the button one time...
            – Oskar Gustavsson
            Nov 13 at 12:26


















          • Thanks for your responses, however im not sure what you mean, my issue is not that its not correct in the XML its that Android 5 doesnt render it correctly until I press it the first time. If you look at the correct picture there are 2 buttons and both of thoose are correct, and they look like that in all android versions above 5. The left ones are from Android 5 where the xml doesnt seem to apply until I press the button one time...
            – Oskar Gustavsson
            Nov 13 at 12:26
















          Thanks for your responses, however im not sure what you mean, my issue is not that its not correct in the XML its that Android 5 doesnt render it correctly until I press it the first time. If you look at the correct picture there are 2 buttons and both of thoose are correct, and they look like that in all android versions above 5. The left ones are from Android 5 where the xml doesnt seem to apply until I press the button one time...
          – Oskar Gustavsson
          Nov 13 at 12:26




          Thanks for your responses, however im not sure what you mean, my issue is not that its not correct in the XML its that Android 5 doesnt render it correctly until I press it the first time. If you look at the correct picture there are 2 buttons and both of thoose are correct, and they look like that in all android versions above 5. The left ones are from Android 5 where the xml doesnt seem to apply until I press the button one time...
          – Oskar Gustavsson
          Nov 13 at 12:26












          up vote
          0
          down vote













          <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
          <item>
          <shape >
          <solid android:color="@android:color/white"/>
          <size android:height="1dp"/>
          </shape>
          </item>
          <item android:bottom="2dip" android:top="2dip" android:left="2dip" android:right="2dip">
          <shape>
          <solid android:color="@android:color/Transparent"/>
          </shape>
          </item>




          this is exactly look like your correct button






          share|improve this answer





















          • See comment above, Im pretty sure its not an XML issue, but something with Android 5
            – Oskar Gustavsson
            Nov 13 at 12:26















          up vote
          0
          down vote













          <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
          <item>
          <shape >
          <solid android:color="@android:color/white"/>
          <size android:height="1dp"/>
          </shape>
          </item>
          <item android:bottom="2dip" android:top="2dip" android:left="2dip" android:right="2dip">
          <shape>
          <solid android:color="@android:color/Transparent"/>
          </shape>
          </item>




          this is exactly look like your correct button






          share|improve this answer





















          • See comment above, Im pretty sure its not an XML issue, but something with Android 5
            – Oskar Gustavsson
            Nov 13 at 12:26













          up vote
          0
          down vote










          up vote
          0
          down vote









          <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
          <item>
          <shape >
          <solid android:color="@android:color/white"/>
          <size android:height="1dp"/>
          </shape>
          </item>
          <item android:bottom="2dip" android:top="2dip" android:left="2dip" android:right="2dip">
          <shape>
          <solid android:color="@android:color/Transparent"/>
          </shape>
          </item>




          this is exactly look like your correct button






          share|improve this answer












          <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
          <item>
          <shape >
          <solid android:color="@android:color/white"/>
          <size android:height="1dp"/>
          </shape>
          </item>
          <item android:bottom="2dip" android:top="2dip" android:left="2dip" android:right="2dip">
          <shape>
          <solid android:color="@android:color/Transparent"/>
          </shape>
          </item>




          this is exactly look like your correct button







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 10:49









          Muhammad Waqas

          32110




          32110












          • See comment above, Im pretty sure its not an XML issue, but something with Android 5
            – Oskar Gustavsson
            Nov 13 at 12:26


















          • See comment above, Im pretty sure its not an XML issue, but something with Android 5
            – Oskar Gustavsson
            Nov 13 at 12:26
















          See comment above, Im pretty sure its not an XML issue, but something with Android 5
          – Oskar Gustavsson
          Nov 13 at 12:26




          See comment above, Im pretty sure its not an XML issue, but something with Android 5
          – Oskar Gustavsson
          Nov 13 at 12:26


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258682%2fcustom-appcompatbutton-getting-wrong-colors-on-android-5-api-21%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          鏡平學校

          ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

          Why https connections are so slow when debugging (stepping over) in Java?