Android Toggle switch's text on the right - android

I had googled around but there seem no way to may the text appears on the right instead of on the default Left. image explained.
May i know is there way to make the text ("sound") appear on the right for Android Switch (Android classify them the same) ?
Switch Button

I don't know Why you are struggling with it but when I tried below code text appears right side of toggle button
<Switch
android:text="Switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/switch1"
/>

Related

Changing text while pressing button android studio

I've tried a tutorial on youtube but it doesn't work,when I click the button nothing happens.
When I press the button I want to Change the layout activity and also to be set on the new layout one random text from lets say other 10 and on this current layout I wanna have the button which will randomly change the first text to another one.
Here is what codes I've used and didn't worked out.
#I can't add the codes because It doesn't let me post it here..it says something like isn't valid but you see everything in the picture,so I did all that code and when I press on my button It doesn't doing anything,what can be the problem?and If you have any idea or if you know any tutorial to help me achieve what I said I want to do upper I would appreciate really much
#as you can see there is a string option which should give me one text of all of them when I click my button,but it doesn't
sorry for image but it seems like those codes aren't good
<LinearLayout
android:layout_width="332dp"
android:layout_height="184dp"
android:layout_marginStart="36dp"
android:layout_marginLeft="36dp"
android:layout_marginTop="48dp"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="#+id/buttonsports"
android:layout_width="match_parent"
android:layout_height="129dp"
android:background="#drawable/ft"
tools:layout_editor_absoluteX="115dp"
tools:layout_editor_absoluteY="291dp" />
<TextView
android:id="#+id/sports"
android:layout_width="216dp"
android:layout_height="117dp"
android:text="TextView"
tools:layout_editor_absoluteX="95dp"
tools:layout_editor_absoluteY="246dp" />
</LinearLayout>
this is how big my text box is,the "sports" is the id for TextView which is "abc"
In your xml you have a LinearLayout for which you have set the height to:
android:layout_height="184dp"
and inside there is a Button with height:
android:layout_height="129dp"
So for the TextView below there is left maximum 55dp but you set:
android:layout_height="117dp"
This means that at least half the TextView is not visible.
In your code you set a random text to the TextView when you click the Button.
You say that nothing happens.
Is there a case that the text is being set but you can't see it because the TextView is mostly hidden?
Change the heights of the views and you will find out.

Unwanted button text outline only in MotoG5

I have simple button
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#d22d2d"
android:text="Proceed"
android:textSize="35sp"
/>
On MotoG5 it shows unwanted outline on Button text, while it is okay in other devices.
This text outline does not appear in TextView. I tested it.
I checked another app in mobile, all apps (Gmail, Contacts etc.) having same behaviour.
I think there should be some theme fix to remove this unwanted outline in MotoG5.
You can disable it from Settings > Accessibility > Set off to High-contrast text
Your problem will solve.

Styling the custom switch in android

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" />

Button appearing differently in AVD/Graphical layout and on a actual phone

I have modified my button to look like a spinner. On the AVD and Graphical layout it appears exactly like a spinner would but on my phone it appears quite different.
Button on the AVD:
Button on my phone:
Can someone tell me why this is happening??
Here is the Button layout in XML:
<Button
android:id="#+id/datebutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="#string/datebuttontxt"
android:onClick="datepicker"
android:gravity="center"
style="#android:style/Widget.DeviceDefault.Light.Spinner" />
Changing the button background to invisible is not helping.
Also, If I use an actual spinner it would appear correctly, just like it shows on the AVD.
Widget.DeviceDefault.X styles change between different devices, use #android:style/Widget.Holo.X styles to get a consistant look and feel.
In your case:
#android:style/Widget.Holo.Light.Spinner

android button fine text alignment

I'm trying to create standard button in android with a background and some text in front but some fairly specific alignment. I want the text to be centered vertically and on the left with 20dp of padding. The alignment works but the padding doesn't. I know I could probably get the desired effect by putting a few spaces in the text but that seems like a hack and next I want to do a similar thing but with the text at the top so I would prefer a more elegant solution.
Here's what I have:
<Button
android:layout_width="312dp"
android:layout_height="95dp"
android:id="#+id/gv_music_button"
android:text="Music"
android:textSize="30sp"
android:paddingLeft="20dp"
android:gravity="left|center_vertical"
/>
My mistake, padding was working correctly. Just didn't appear to be.

Categories

Resources