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 7830461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:14:34+00:00 2026-06-02T11:14:34+00:00

I have an xml file with a selector in it that defines the different

  • 0

I have an xml file with a selector in it that defines the different states for a button:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/custom_green_button_selected_state" />
<item android:state_enabled="false" android:drawable="@drawable/custom_green_button_disabled_state" />  
<item android:drawable="@drawable/custom_green_button_normal_state"/>
</selector>

Then in each of my drawable xmls I have information on how the button looks like this:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:type="linear" android:gradientRadius="180"
    android:startColor="#6b9f41" android:endColor="#598a3d" />

<corners android:bottomRightRadius="7dp"
    android:bottomLeftRadius="7dp" android:topLeftRadius="7dp"
    android:topRightRadius="7dp" />
<padding android:left="15dp" android:right="15dp" android:top="10dp"
    android:bottom="10dp" />
</shape>

For most of the buttons in my app I just apply the first xml as the background and everything works fine. For a specific button, I’d like to use the same xmls but make the button skinnier by changing the padding of the drawables. I thought I’d try creating a new StateListDrawable in my code and adding a mutate of each of the individual state’s drawable xmls, however, these drawables show up as GradientDrawables which doesn’t seem to give me access to their padding properties. Any ideas?

  • 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-02T11:14:36+00:00Added an answer on June 2, 2026 at 11:14 am

    Padding of background drawable are also set by setPadding in View class.

    You can set padding by calling setPadding after setBackgroundDrawable.

    Here is core/java/android/view/View.java:

    /**
     * Set the background to a given Drawable, or remove the background. If the
     * background has padding, this View's padding is set to the background's
     * padding. However, when a background is removed, this View's padding isn't
     * touched. If setting the padding is desired, please use
     * {@link #setPadding(int, int, int, int)}.
     *
     * @param d The Drawable to use as the background, or null to remove the
     *        background
     */
    public void setBackgroundDrawable(Drawable d) {
        boolean requestLayout = false;
    
        mBackgroundResource = 0;
    
        /*
         * Regardless of whether we're setting a new background or not, we want
         * to clear the previous drawable.
         */
        if (mBGDrawable != null) {
            mBGDrawable.setCallback(null);
            unscheduleDrawable(mBGDrawable);
        }
    
        if (d != null) {
            Rect padding = sThreadLocal.get();
            if (padding == null) {
                padding = new Rect();
                sThreadLocal.set(padding);
            }
            if (d.getPadding(padding)) {
                setPadding(padding.left, padding.top, padding.right, padding.bottom);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a XML file: <?xml version=1.0 encoding=utf-8?> <selector xmlns:android=http://schemas.android.com/apk/res/android> <item android:state_pressed=true android:drawable=@drawable/calender_h
Having this selector XML file: <?xml version=1.0 encoding=utf-8?> <selector xmlns:android=http://schemas.android.com/apk/res/android> <item android:state_pressed=true android:drawable=@drawable/z01_pressed />
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have one ImageButton in my xml layout like that : <ImageButton android:id=@+id/tabsButton android:background=@drawable/button
I have an xml file providing data for a datagrid in Flex 2 that
I have a XML File like that <?xml version=1.0 encoding=utf-8 ?> <Configurations> <EmailConfiguration> <userName>xxxx</userName>
I have created a custom Button as follows. file : buttoncontrol.xml <?xml version=1.0 encoding=utf-8?>
I have the following selector defined in an XML file under res/color/redeemlist_item_color.xml : <?xml
I have an android application that has a button which I want to have
What is the easiest way to convert xml to html? I have xml file

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.