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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:44:47+00:00 2026-05-27T23:44:47+00:00

A ToggleButton widget changes size when the checked state is toggled. For example, if

  • 0

A ToggleButton widget changes size when the checked state is toggled. For example, if the textOn value is “true” and the textOff value is “not sure call me later”, a checked state toggle causes the button width to change dramatically.

It would be nice to set the width of a ToggleButton to the maximum of the two content-wrapped widths created by textOn and textOff.

Is there a preferred way to maintain constant ToggleButton width? Is the best way to simply call getWidth(), then toggle(), then getWidth() again?

  • 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-05-27T23:44:48+00:00Added an answer on May 27, 2026 at 11:44 pm

    Because its a button with just two strings, there is no harm in providing the width in the XML itself according to the larger string.

    But if you want to calculate the width of the strings, it’s simple:

    Paint paint = toggleButton.getPaint();
    float length = paint.measureText(YOUR_STRING);
    

    This gives you the width of the string it would take on the screen. Now set the width of the toggle button via LayoutParams.

    Lets say parent layout of your toggle button is LinearLayout.
    so it should go like:
    toggleButton.setLayoutParams(new LayoutParams(WIDTH_YOU_CALCULATED, LinearLayout.LayoutParams.WRAP_CONTENT));

    This will set the width and height of your ToggleButton to what you calculated.

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

Sidebar

Related Questions

Within a Desktop app I have a toggle button: <ToggleButton x:Name=CFStglBtn Checked=cfsCBox_Checked Unchecked=cfsCBox_Unchecked IsChecked=True
Here is my XAML: <Style x:Key=ExpanderStyle TargetType={x:Type ToggleButton}> <Setter Property=IsEnabled Value=True /> <Setter Property=Template>
I have a togglebutton which is not responding to my setChecked(...) method. Here is
We have a simple animation that runs when a ToggleButton is checked and unchecked
I want a widget that behaves like a togglebutton and can have its background
I have a ToggleButton, when you click it, I don't want the state to
I want to define a ToggleButton that appears with red foreground (for example) when
possible duplicate, hello all, I am not getting the reason that why ToggleButton was
Here is what i am trying to do private ToggleButton _itemChecked=Name_Of_Element_In_Xaml; That doesnt work.
There is something I'm just not getting, and I'm looking for assistance in understanding

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.