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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:05:29+00:00 2026-06-08T09:05:29+00:00

i want to create a android default ToggleButton like this: but i want to

  • 0

i want to create a android default ToggleButton like this: enter image description here

but i want to create it without TEXT

I tryed with this code:

ToggleButton tb = new ToggleButton(map);
tb.setText(null);
tb.setTextOn(null);
tb.setTextOff(null);

But it is leaving a empty space in the top of the horizontal green bar.

I dont want that empty space, i only want the horizontal green bar.

How to achieve it?

thanks

  • 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-08T09:05:30+00:00Added an answer on June 8, 2026 at 9:05 am

    The empty space in the top is caused by the 2 Ninepatch (btn_toggle_off.9.png and btn_toggle_on.9.png ) used in default toggleButton style.

    To perfectly center the horizontal bar, you must create a new style for ToggleButton that will use two new ninepatch derived form original.

    Edit:
    Method requiring minimal XML:

    • create your two ninepatches for your togglebutton, name it: my_btn_toggle_on and my_btn_toggle_off

    • in drawable folder, create my_btn_toggle.xml:

      <selector xmlns:android="http://schemas.android.com/apk/res/android">
          <item android:state_checked="false" android:drawable="@drawable/my_btn_toggle_off" />
          <item android:state_checked="true" android:drawable="@drawable/my_btn_toggle_on" />
      </selector>
      
    • in your code, add tb.setBackgroundResource(R.drawable.my_btn_toggle) :

      ToggleButton tb = new ToggleButton(map);
      tb.setText(null);
      tb.setTextOn(null);
      tb.setTextOff(null);
      tb.setBackgroundResource(R.drawable.my_btn_toggle)
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a new web-browser for android, but this browser is not
I want to create a twitter application in Android. For this I want to
I want to create an android application that a user can use to text
I want to create an Android app that can be used on 2.3.3 all
I want to create an Android application that show the sales report from SQL
I want to create a android search application that can be used to search
I want to find out if it is possible to create Android API's that
So, I want to create a custom Android TextView with a border INSIDE AN
I want to create a layout for an Android app that has a numeric
Possible Duplicate: Android: How to create slide (on/off) button I want to create sliding

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.