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

  • Home
  • SEARCH
  • 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 9015339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:43:40+00:00 2026-06-16T03:43:40+00:00

<ToggleButton android:id=@+id/toggle android:layout_width=wrap_content android:layout_height=wrap_content android:background=@drawable/check android:layout_margin=10dp android:textOn= android:textOff= android:focusable=false android:focusableInTouchMode=false android:layout_centerVertical=true/> <?xml version=1.0 encoding=utf-8?>

  • 0
<ToggleButton 
        android:id="@+id/toggle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/check"   
        android:layout_margin="10dp"
        android:textOn=""
        android:textOff=""
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_centerVertical="true"/>

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/selected_image"
          android:state_checked="true" />
    <!-- When not selected, use white-->
    <item android:drawable="@drawable/unselected_image"
        android:state_checked="false"/>

 </selector>

How can use a color instead of a drawable?

I tried this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_checked="true" android:color="@color/bg_blue"/>
    <item android:state_checked="false" android:color="@color/bg_light_grey"/>

</selector>

defined the above selector in color folder with name bg_toggle.xml

and

android:background="@color/bg_toggle"

which gives an Exception:

android.view.InflateException: Binary XML file line #50: Error inflating class android.widget.ToggleButton

org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: tag requires a ‘drawable’ attribute or child tag defining a drawable

Thank You

  • 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-16T03:43:41+00:00Added an answer on June 16, 2026 at 3:43 am

    try this

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

    EDIT

    From android Doc

    Note: A color resource can also be used as a drawable in XML. For example, when creating a state list drawable, you can reference a color resource for the android:drawable attribute (android:drawable=”@color/green”).

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

Sidebar

Related Questions

This my main.xml <RelativeLayout android:id=@+id/gloabal_permission android:layout_height=fill_parent android:layout_width=wrap_content android:background=@drawable/settings_selector_down android:paddingTop=3dp android:paddingBottom=3dp android:paddingRight=12dp android:paddingLeft=15dp> <TextView android:id=@+id/TextView06
<RelativeLayout android:layout_width=fill_parent android:layout_height=50dip> <Button android:text=Edit android:width=50dip android:layout_height=fill_parent android:layout_width=wrap_content android:layout_alignParentLeft=true android:layout_alignParentTop=true /> <ToggleButton android:textOn=All android:textOff=Wishlist
in my xml file i have this button : <Button android:id=@+id/button_8 android:layout_width=0dp android:layout_height=wrap_content android:text=@string/Bf
My android apps has a regular button: <Button android:id=@+id/allOnButton android:layout_width=wrap_content android:layout_height=wrap_content android:layout_marginRight=130dp android:text=@string/sensor_management_all_on />
Possible Duplicate: ToggleButton state change programmatically rather than automatically in Android? I am trying
I customized the Toggle button by using a drawable defined by using a selector.
Anyone know of any open source implementation of a slide toggle for android. The
How do I get the position of the android togglebutton that was clicked in
I'm new developing on Android. I'm have a view with a ToggleButton on it
I need to toggle existing android contacts to favourite. I have a toggle button

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.