0

I have a switch and i need the text within the switch(Eg: ON/OFF) to be ellipsized if long. How can it be done?The following does not work!!

<Switch
                android:id="@+id/switch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right|center_vertical"
                android:layout_centerVertical="true" 
                android:paddingBottom="5dp"
                android:layout_alignParentRight="true"
                android:minWidth="80dp"
                android:minHeight="18dp"
                android:textOff="@string/toggle_off"
                android:textOn="@string/toggle_on"
                android:ellipsize:end
                android:maxWidth="50dp"
                android:singleLine="true"
                 >
            </Switch>
user584263
  • 375
  • 5
  • 18

1 Answers1

0

Add this code in your java file:

    Switch switch = (Switch) vi.findViewById(R.id.switch);
    switch.setEllipsize(TextUtils.TruncateAt.END);
    switch.setSingleLine(true);
Jainendra
  • 24,713
  • 30
  • 122
  • 169