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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:01:49+00:00 2026-06-12T17:01:49+00:00

I customized the Toggle button by using a drawable defined by using a selector.

  • 0

I customized the Toggle button by using a drawable defined by using a selector. I use this drawable as background for the Toggle button.

<ToggleButton
    android:id="@+id/mailbox:toggle_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_weight="1"
    android:background="@drawable/toggle_background"
    android:gravity="center_horizontal|center_vertical" />

The toggle_background is defined here:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:drawable="@drawable/img1"
            android:state_checked="true" />
        <item
            android:drawable="@drawable/img2"
            android:state_checked="false" />    
    </selector>

The problem is that the image is always stretched. Is there a way to define an image for the two states that is not stretched?

What I need is a background that will be stretched and in the center of the button an icon that must not be stretched.

Is it possible?

  • 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-12T17:01:50+00:00Added an answer on June 12, 2026 at 5:01 pm

    I did the same task this way, the button:

            <ToggleButton  android:id="@+id/mlAbout"
                android:textOn="@string/about"
                android:textOff="@string/about"
                android:background="@drawable/ml_about" />
    

    @drawable/ml_about:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:drawable="@drawable/list_bg_top"></item>
        <item android:left="10dp">
            <bitmap android:src="@drawable/waiting_status_btn"
              android:gravity="center_vertical|left" />
        </item>
    </layer-list>
    

    @drawable/list_bg_top background image that will be stretched and @drawable/waiting_status_btn is the icon the will not be stretched with the widget

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a customized show/hide toggle script that I'm using along with CSS3 transitions
I customized a header view in a ListView by using xml file, this file
I have customized the button in this way: <Button BorderBrush=Transparent Name=DialButton Click=DialButton_Click > <StackPanel
I am using a customized version of FingerPaint for Android with some other features,
I am trying to use a Switch (toggle) in android 4.0 API. If I
How to create customized tab-bars in android not using images ? I need to
I want to use customized template for hg log which looks like this: hg
I'm using a customized version of the vhost connect/express middleware and inside it I
I have found and customized this JQuery script, which displays different content when different
When a class is customized, by using its outlet , you cant access its

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.