I am trying to create a listview with switches. It is working; but not as how i expected it to be. The text ON/OFF is written inside the circle(slider) and not behind it which looks awkward. I cannot find a way on how to put the text behind the slider and i tried searching but it seems that no one is experiencing this problem aside from me.
Also, is there a way where i can edit the custom switch or am i obliged to use android:background like what others are doing base on my research. (I am avoiding to use background because i am not good at Photoshop).
Thank you in advance!
You can have 9 patch images for switch
<Switch
android:id="#+id/switch_bg2"
android:layout_width="92dp"
android:layout_height="24dp"
android:checked="true"
android:focusable="false"
android:textOff="O"
android:textOn="I"
android:thumb="#drawable/switch_thumb"
android:track="#drawable/switch_bg"
android:typeface="sans" />
Related
So, this question is a duplicate, but the answers I have read doesn't work for me. If fact, they don't seem to have worked for other people either, so I'll give it another shot and see if someone knows the answer.
When Adding a textView, it looks like
As you can see there is definitely a lot of space between the blue layout-marking and the actual text. When placing one textView on top of another the space becomes quite noticeable. Note that this is after I have added the XML code lines:
android:includeFontPadding="false"
(Which works to a small extent) and:
android:lineSpacingExtra="0dp"
(Which is said to solve the problem according to other threads, but does nothing for me for some reason).
The full XML for my textView is:
<TextView
android:id="#+id/healthTextId"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:includeFontPadding="false"
android:lineSpacingExtra="0dp"
android:text="Test"
android:textAlignment="center"
android:textColor="#color/colorHealth"
android:textSize="100dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
The problem persists on both default and custom fonts. Any ideas?
This is one of the threads I read that unfortunately didn't solve the issue for me: Android: TextView: Remove spacing and padding on top and bottom
This problem is very annoyying. Even if you remove all paddings, the padding of the font itself remains. Try this answer. This is a good approach.
Just android:padding="0dp" should work.
I'm really confusing how the android's design/front-end works. A lot of questions are in my mind that, why android not provider easy way/method ( as in html like border-bottom, or in JavaFX) to add borders in textview or something other blah blah. but afraid may be stackoverflow not allowed me ask such question. One question of them which I want to ask here is that what is required to use android:backgroundTint
Because in the EditText it is working as simple.
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edting"
android:backgroundTint="#00FFFF"
/>
but in the TextView to work with it or to add the border I have to use a drawable utility.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edting"
android:backgroundTint="#00FFFF" // not working at all
/>
Somewhere I read that it add the shade to background. But why it is changing the bottom-border. So another question could be the actual purpose of android:backgroundTint
I've read through both of these questions, which seem to have the same problem i'm struggling with, namely I have text for my buttons that i'd like to display as a superscript. In my fragment class in the onCreateView method I have added
if (rootView.findViewById(R.id.squared) != null) {
((TextView) rootView.findViewById(R.id.squared)).setText(Html.fromHtml("X <sup><small> 2 </small></sup>"));
rootView.findViewById(R.id.squared).setOnClickListener(this);
}
if (rootView.findViewById(R.id.cubed) != null) {
((TextView) rootView.findViewById(R.id.cubed)).setText(Html.fromHtml("X <sup><small> 3 </small></sup>"));
rootView.findViewById(R.id.cubed).setOnClickListener(this);
In my fragment_main the buttons are coded as
<Button
android:layout_height="match_parent"
android:layout_width="0dp"
android:fontFamily="helvetica"
android:id="#+id/squared"
android:layout_weight="0.25"
style="?android:attr/borderlessButtonStyle"
android:textSize="15sp" />
<Button
android:layout_height="match_parent"
android:layout_width="0dp"
android:fontFamily="helvetica"
android:id="#+id/cubed"
android:layout_weight="0.25"
style="?android:attr/borderlessButtonStyle"
android:textSize="15sp" />
However, when I run my application the layout doesn't any superscripted text.
Even when I change the text size from 15sp to 10sp, the text only gets smaller, but not superscripted. What am I not doing correctly?
I'd comment if I could, but at this point I can't. I JUST posted something similar to this, an issue I'm having as well. I had my problem solved halfway. The method Html.fromHtml works for me only on a textview, but not on my butons. I just wanted to say this in case it helps you or anyone else figure out how to employ this method on the buttons. I'd very much like the answer myself.
Basically:
textview.setText(Html.fromHtml("x<sup>2</sup")); displays properly
BUT button.setText(Html.fromHtml("x<sup>2</sup")); displays x2 (without superscript).
EDIT: AlanV helped me out. Here's a link to the solution he provided someone else. https://stackoverflow.com/a/29056795/4535064
All you need to do is add this to your button:
<button
android:textAllCaps="false";/>
The new version 5.0 (I think) forces buttons to produce all caps. This is something I noticed when I produce the same string in a textview and button, and the button was all caps whereas the textview was not. Because of this, you don't see the HTML formatting such as and . Setting the textAllCaps feature to "false" allows the HTML to be utilized.
Again, giving credit where it's due, AlanV is the man! :-)
This is a known issue, as shown here.
I think the best thing to do is to set android:textAllCaps="false" , and then to set the text to be capitalized by yourself.
After some pretty thorough googling I still cannot figure out what the the little graphic that's displayed under the text in and EditText View is called. I would also like to remove it either using XML or programmatically. The little graphic is the thing under the cursor in this image: http://1.bp.blogspot.com/-UAuOq0h4Vok/T8reinvaWPI/AAAAAAAABPc/N4yibXd3kZg/s1600/android%2Bedittext%2Btext%2Bchange%2Blistener%2Bexample.jpg . Sorry if this is a dumb question, but without the name of this little graphic feature I can't seem to find out anything about it.
It is the background drawable associated with the edittext. You can change it by manually setting the background to something yourself, such as
<EditText
android:background="#android:color/transparent"
...
/>
Try this..
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/hello"
android:background="#00000000"
/>
if you want transparancy just put 80 before the actual hash code.
#80000000
This will change any colour you want to transparent one.. :)
you probably have in your layout
android:minLines="2"
try to remove it
This is my XML for my check box:
<CheckBox
android:id="#+id/atm_checkbox"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/input_color" />
And it looks like this:
http://imageshack.us/photo/my-images/528/47342915.png/
This is what i found on internet:
<CheckBox
android:id="#+id/chkAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/chk_android"
android:checked="true" />
which looks like this
how to change my checkbox to look like the one i found on internet.
As my rep is <10 i cant upload image of my checkbox, or can anyone help me how to style checkbox to make it look better
I think both the xmls have similar code, but why are they looking so different?
If you want custom the look of checkbox see this tutorial and find everything.
By the way, the checkbox from your link is for Android3.0 and above.
CheckBox derive from Button class, so you can set a background image like button. See this link, may be it is what you are looking for.
If you want a clean design without codes, use:
<CheckBox
android:id="#+id/checkBox1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:drawableLeft="#android:color/transparent"
android:drawablePadding="10dp"
android:text="CheckBox"/>
The trick is to set colour to transparent for android:drawableLeft and assign a value for android:drawablePadding. Also, transparency allows you to use this technique on any background colour without the side effect - like colour mismatch.