How to set the text for custom made toggle button android - android

how to add the text "on" & "off" for the toggle button ?
Do we need to add text also in image ?

You have a few options.
Make your graphic larger and include the text.
Use a LinearLayout and incorporate two TextViews around your ImageView.
Subclass your overall view and draw the text in onDraw().

If you are using XML to generate the toggle button you would use android:textOn and android:textOff in your ToggleButton<>
Source:
http://developer.android.com/reference/android/widget/ToggleButton.html#attr_android:textOn

Related

I want to add the font settings to my edittext

I want to add text on the image. for that I want to add font settings to my text. like add color, font styles etc..
. Can any one share the code.
I want exactly this kind of layout with source code:
You can use Framelayout to overlap views
or you can use a CardView as well.

toggle button height less than 30dp text disappears Android

I am having quite a challenge with this. If the toggle button height is less than 30dp, the text disappears.
I am wondering is this a design issue or can anyone help me with a workaround?
You could try setting the padding to 0. Sometimes you need to override the default padding.
If that doesn't do the job you can use custom graphic instead of android default graphic. The default toggle button graphic for android is 9-patch and in this there is some build in padding you can't disable from code.
You could try to setIncludeFontPadding to false. This can be done both in code and xml.
As a last resort you have to change the textsize in order to fit inside the button.

Android UI: setting background color for Button prevents it from highlighting upon press

I need to eliminate the gap between buttons in a layout. I'm doing it by setting background color for a style and applying that style to my buttons. This eliminates the highlighting upon press, which I of course need. Here is a solution to this problem, but it requires extra actions to be taken with Java code. Can I make it statically, only with XMLs?
Also, if there is any other way to remove the gap without changing the other aspects of button's appearance - please suggest. The only requirement is it should be done with XML (however, if no other options exist, I can inherit Button class).
You can use StateList xml for background of your button

Android how to position toggle button light

`
Hi,
I have requirement of using my own background and blue light for toggle button.
However, using this i am not able to custom position light of toggle button which is always placed to the bottom of button.
I want to move it above and just below center of button.
I tried with paddingBottom but that did not help. Any help regarding this appreciated.
-Thanks,
Manju
That light is part of the nine-patch png. If you create new backgrounds, you need to add your own "on" and "off" circles to the file. You then use the border lines of the nine-patch to prevent stretching of the circle.
http://developer.android.com/guide/developing/tools/draw9patch.html
Read also my answer here for another explanation: How to create android spinner without down triangle on the right side of the widget
Use a LayerList and position the graphic on the toggle button by enclosing the drawable in a bitmap tag, and set its gravity to 'center' - see LayerList here
Use a relativeLayout and do android:layout_Below, if I understand your question correctly

I Want to create custom Circular Button which will Focus on click how to do?

I am trying to create one custom button which is circular and when i click that button i want that button FOCUS and COLOR change and i don't know how to do exactly so any one can help me or show me that code how to do?
You can use a regular Button and specify custom Drawable for it and then apply it to the Background property of the button. See the ApiDemos for examples of styling controls.
You can use two (or more) drawables for one Button and change the drawables in various states (focus, press, etc). Look at this: http://blog.androgames.net/40/custom-button-style-and-theme/

Categories

Resources