Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7896529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:55:05+00:00 2026-06-03T07:55:05+00:00

I know there are similar post to this but I couldn’t find my answer

  • 0

I know there are similar post to this but I couldn’t find my answer in any of them. So, I have this drawable XML:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
    <bitmap
        android:src="@drawable/bm_btn_background"
        android:tileMode="repeat"
        android:gravity="center" />
</item>
<item android:state_enabled="true">
    <shape android:shape="rectangle">
        <gradient
            android:startColor="#a0e0b071"
            android:endColor="#a0a67637"
            android:angle="270" />
        <stroke
            android:width="1dp"
            android:color="#5c3708" />
        <corners
            android:radius="5dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />
    </shape>
</item>
<item android:state_pressed="true" >
    <shape>
        <gradient
            android:startColor="#a0a67637"
            android:endColor="#a0e0b071"
            android:angle="270" />
        <stroke
            android:width="1dp"
            android:color="#5c3708" />
        <corners
            android:radius="5dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />
    </shape>
</item>

I am trying to create a button with a repeated image as background and a gradient applied to it. With this code I only see the background image, not the gradient nor the border and the rounded corners. Also, when I click the button, it doesn’t change (the gradient is supposed to change). I don’t know what is wrong with this code? If instead of a selector I use a layer-list, I get the desired result but it doesn’t change either when I press the button. Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:55:06+00:00Added an answer on June 3, 2026 at 7:55 am

    Your code for the selector is wrong because:

    • You have two elements for the same state and as the selector encounters the first state(state_enabled) for the Bitmap element it will stop there and your gradient will never appear(for this you should use a layer-list that has as items the Bitmap and the gradient on top)

    • The selector will match states in order. As you press the Button the state_pressed will never be activated because the selector will match first the state_enabled that is on the first element(for this you should move the code for the state_pressed above the state_enabled elements).

    In fact you should just remove the state_enabled and let the Bitmap + gradient be the default value for the Button. Bellow is your selector(I assumed you only want to change gradient on the image(but the image should appear even in the pressed state, if this isn’t the wanted behavior leave only the gradient for the state_pressed)):

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:state_pressed="true">
            <layer-list>
                <item>
                    <bitmap android:gravity="center" android:src="@drawable/bm_btn_background" android:tileMode="repeat" />
                </item>
                <item>
                    <shape>
                         <gradient android:angle="270" android:endColor="#a0e0b071" android:startColor="#a0a67637" />
                         <stroke android:width="1dp" android:color="#5c3708" />
                         <corners android:radius="5dp" />
                         <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
                    </shape>
                </item>
            </layer-list>
        </item>
    
        <item android:state_enabled="true">
            <layer-list>
                <item>
                    <bitmap android:gravity="center" android:src="@drawable/bm_btn_background" android:tileMode="repeat" />
                </item>
                <item>
                    <shape android:shape="rectangle">
                        <gradient android:angle="270" android:endColor="#a0a67637" android:startColor="#a0e0b071" />
                        <stroke android:width="1dp" android:color="#5c3708" />
                        <corners android:radius="5dp" />
                        <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
                    </shape>
                </item>
            </layer-list>
        </item>
    
    
    </selector>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there have been some similar questions to this, but they haven't helped
I know there are many questions similar but any of them didn't help. in
I know there a lot of similar questions to this, but I didn't find
I know there are questions similar to this one, but I've not found a
First of, I know there are similar questions already on stackoverflow ( this ,
I know there is a very similar question here but I was hoping to
I know there are a lot of similar questions on SF, but I think
I know there are several threads asking similar questions - but I havent found
I know there's like 3-5 similar questions here, but non of the answers solves
I know there are a lot of questions similar to mine, but I actually

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.