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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:46:51+00:00 2026-05-25T10:46:51+00:00

So I started looking at extending the ToggleButton so I could in addition to

  • 0

So I started looking at extending the ToggleButton so I could in addition to using states in the selector, I wanted to also draw on top of it. As I was going though this I realized that there seems to be an issue with the height and layout_height, which I might be missing something…

tbutton

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

now inside the layout xml (snippit of course)

    <ToggleButton android:id="@+id/mytoggle1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/tbutton"
              android:textOn=""
              android:textOff=""
              android:layout_weight="0"
              android:focusableInTouchMode="false"
              android:focusable="false"
              android:layout_marginRight="@dimen/PADDING"/>

    <edu.ninjacore.components.codeToggle android:id="@+id/mytoggle2"
                         android:layout_height="wrap_content"
                         android:layout_width="wrap_content"
                         android:focusable="false"
                         android:focusableInTouchMode="false"
                         android:layout_weight="0"/>

in the create of codeToggle I have in the constructor (nothing fancy)

    public codeToggle(Context context)
    {
        super(context);
        setBackgroundDrawable(getResources().getDrawable(R.drawable.tbutton));
    }

What you’ll find is that the codeToggle will have a different height than the ToggleButton height… it’s like there is a slew more padding on the top and bottom.

Why is that, and how would you correct it?

Thanks,
Kelly

  • 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-25T10:46:51+00:00Added an answer on May 25, 2026 at 10:46 am

    I found out the solution was rather simple, as I wasn’t going to the right location for width and height.

    What you should use is the:

        getBackground().getBounds()
    

    Doing this it will allow you to resize whatever you want to draw and position based on the constraints of the current item (in this case the ToggleButton)

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

Sidebar

Related Questions

I've been using Seam 2 (also started looking into Java EE 6) in my
I recently started looking into building web applications using .NET MVC and I stumbled
Just started looking into encryption using keys and certificates in sql server 2005/08 and
I just started looking into Raphael, and every tutorial said that you may draw
I´ve recently started looking a web service calls using PHP. I can´t get the
I have recently started looking into using Azure but I'm having some issues getting
I started looking at using proto-buf .Net for my serialization needs for media browser.
I just got started looking at using Solr as my search web service. I
I have just started looking into using Modules in Flex and would like to
We've just started looking at using JBehave for acceptance tests and I was wondering

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.