Show to set text visible in OFF state at SwitchCompat? - android

Currently my SwitchCompat looks like the image below (the top portion), however I need to have visible text in OFF state.
How would I achieve this?

Are you using background images? if it does you need set text on images not on switch.

<android.support.v7.widget.SwitchCompat
android:id="#+id/autoLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/colorPrimary"
android:checked="false"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="10dp"
android:text="#string/autoLocation"
android:textColor="#ffffff"
android:textOff="Off"
android:textOn="On"
android:textSize="20sp"
app:showText="true" />

Related

How to make TextView in Android wrap and adjust text beautifully?

When text is small then I get this:
But when text is big I get this:
Is it possible that text adjust itself by maybe better using spaces or decreasing little size automatically?
This is my TextView xml:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/seaGreen"
android:gravity="center_vertical"
android:padding="10dp"
android:textColor="#color/white"
android:textSize="35sp" />
For that you need to use external library for that, else you can set gravity as center
Library :
https://github.com/grantland/android-autofittextview
For Text Justify
https://github.com/bluejamesbond/TextJustify-Android
https://github.com/programingjd/justified
OR
you can check this answer
this work for me:
<TextView
android:id="#+id/your_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:textAlignment="center"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="14sp"/>

Padding in android, untidy my layout

I have this layout inside a linerar layout (It is a custom Dialog), and when i add padding in the buttons, my layout become untidy.
<RadioGroup
android:id="#+id/toggleGroupEntrega"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ToggleButton
android:id="#+id/toggleButtonEntregaOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/bgOff"
android:checked="false"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="#string/entrega_ok"
android:textOff="#string/entrega_ok"
android:textOn="#string/entrega_ok" />
<ToggleButton
android:id="#+id/toggleButtonEntregaRecusa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/bgOff"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="#string/entrega_recusa"
android:textOff="#string/entrega_recusa"
android:textOn="#string/entrega_recusa" />
<ToggleButton
android:layout_margin="5dp"
android:id="#+id/toggleButtonEntregaAvaria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/bgOff"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="#string/entrega_avaria"
android:textOff="#string/entrega_avaria"
android:textOn="#string/entrega_avaria" />
</RadioGroup>
that are the result:
if i remove android:paddingLeft="5dp" and android:paddingRight="5dp", works well, but i really wanna a padding inside the elements(I do not want the text along the edges).
Why it happens? (have alot of free space if you see compelte image)
i wanna that way, but with a lite bit more padding (in this case, have only 2dp):
Issue here is not padding, the issue here is that when you adding it last ToggleButton doesn't fit first line, and when it goest to the next one this happens. So as Der Golem said :
Try using proper casing. Or a smaller font size
The other thing, you can add
android:singleLine="true"
android:ellipsize="end"
to your last item, that way you can undestand what causes the issue in your case
EDIT : with following layout you can't reach your goal(unfortunetly)

Remove Background of image in Button which has Image and text in Android

i have a big buttons with images and text.i want to remove white background behind image.
Xml code:
<Button
android:id="#+id/message"
android:background="#drawable/button_style"
android:shadowColor="#f9f9f9"
android:drawableLeft="#drawable/message"
android:paddingLeft="20dp"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="1"
android:text="Message"
android:textColor="#52595C"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginTop="2dp" />
i am trying this to remove background but it not working
android:background="#null"
Any Help will be much Apeaciated!
If you want to button to be transparent, use this:
android:background="#00000000"
If you want to image to have a transparent background, you have to use a transparent png file, like this: http://content.mediastg.net/dyna_images/agents/225/137213/20140920014206.png
If you want to learn how to make transparent images:
https://www.youtube.com/watch?v=r17b_QK_9Ng
<ImageButton
android:id="#+id/message"
android:src="#drawable/button_style"
android:shadowColor="#f9f9f9"
android:drawableLeft="#drawable/message"
android:paddingLeft="20dp"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="1"
android:text="Message"
android:textColor="#52595C"
android:layout_width="match_parent"
android:layout_height="130dp"
android:background="#android:color/transparent"
android:layout_marginTop="2dp" />
This maybe work,set android:background="#android:color/transparent" To avoid use background twice, you can use ImageButton to replace Button and use android:src to set the picture as background

Alternate ListItem Styles

I'm trying to make a list_item_view similar to
can anybody help me create it...
What i have tried
made separate view for the list items i.e list_item_even and 'list_item_odd'
for brevity i'll only show one of them, below is the code for list_item_even
<TextView
android:id="#+id/displaysms_lastmsgtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/displaysms_contactname"
android:layout_below="#+id/displaysms_contactname"
android:gravity="right"
android:text="88:88"
android:textColor="#10bcc9"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/displaysms_msgtext"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageButton1"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageButton1"
android:background="#fff"
android:shadowColor="#color/textShadow"
android:shadowDx="1"
android:shadowDy="1"
android:text="hi"
android:textColor="#color/textColor"
android:textSize="16sp" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/displaysms_lastmsgtime"
android:src="#android:drawable/btn_star" />
<TextView
android:id="#+id/displaysms_contactname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="45dp"
android:layout_toRightOf="#+id/displaysms_msgtext"
android:text="john"
android:textColor="#fff"
android:textSize="15sp"
android:textStyle="bold"
android:typeface="sans" />
and here is output
is it possible to create the yellow icon without using image and place an image inside it?
plaese help, Regards
is it possible to create the yellow icon without using image and place
an image inside it?
Maybe, but why put an unnecessary constraint on yourself? You can use a 9patch drawable for the yellow background thing if you're worried about stretching the pointed part. You can learn all about 9patch here.
i think you better off defining the layout programatically and check the row number if odd use one layout if even use a different one
if (row%2==0) use one layout
else use a different one

How do you remove the extra inner padding inside a Spinner button in an Android layout?

I am trying to create a Button that looks like a Spinner.
I have done this by creating a Button like this:
<Button
android:id="#+id/dateButton"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/dateLabel"
android:text="default text"
android:textSize="15sp"
style="?android:attr/spinnerStyle"
android:gravity="center_vertical|center_horizontal" />
The problem is that the text ("default text") inside the Button seems to have extra padding around it, which makes the Button look bloated and expanded in its height.
I thought that setting the layout_height for the button to "wrap_content" would fix this and make the button thinner, but it does not have any effect.
Does anyone know how to make this button's height wrap to the text inside it?
Here is the example code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp" >
<TextView
android:id="#+id/dateLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:text="Select date:"
android:textSize="15sp" />
<Button
android:id="#+id/dateButton"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/dateLabel"
android:text="default text"
android:textSize="15sp"
style="?android:attr/spinnerStyle"
android:gravity="center_vertical|center_horizontal" />
</RelativeLayout>
android:gravity="center_vertical|center_horizontal" instead of this you can write
android:gravity="center" but as per your requirment just remove this line.do not add any gravity and change your height size android:layout_height="40dp"
i changed your code
<Button
android:id="#+id/dateButton"
android:layout_width="150dp"
android:layout_height="35dp"
android:layout_toRightOf="#+id/dateLabel"
android:text="default text"
style="?android:attr/spinnerStyle"
/>
The padding of this button is decided by the drawable of it. You either need to change the spinner drawable (can be done at runtime) , or provide your own drawable to the given button that would make it look like a spinner, without using the default one

Categories

Resources