2015-02-18 16 views
7

Nella mia applicazione Android ho usato il pulsante interruttore c'è comunque per nascondere il testo del pulsante interruttore, Per il livello API 21 c'è un'opzione per nascondere (android: showText) ma ho bisogno di eseguirlo su dispositivi di livello inferiore di seguito è il mio xml:Nascondi testo predefinito per tasto Android Pulsante

<Switch 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="7dp" 
     android:background="@drawable/offbuttonbg" 
     android:textAppearance="@style/SwitchTextAppearance" 
     android:thumb="@drawable/switchselector" /> 
+3

imposta stringa vuota su textOff, textOn ..., forse ... la soluzione più semplice .... – Opiatefuchs

+0

Sono d'accordo, vedere un esempio di risposta di seguito. – Nullpoint

+0

Sì, ho una domanda molto stupida, comunque grazie per la tua risposta veloce – Madhu

risposta

9

per la versione più bassa, per nascondere il testo utilizzare

<Switch 
      android:layout_width="100dp" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="7dp" 
      android:textOff="" 
      android:textOn="" 
      android:background="@drawable/offbuttonbg" 
      android:textAppearance="@style/SwitchTextAppearance" 
      android:thumb="@drawable/switchselector" /> 
+0

qual è il problema con la mia risposta? – Fahim

0

Hai due opzioni uno tramite codice un'altra via XML.

Via Codice:

yourSwitch.setTextOff("textWhenOff") //Sets the text when the component is not in checked state. 

yourSwitch.setTextOn("textWhenOn") //Sets the text when the component is not in checked state. 

XML

<Switch 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="7dp" 
     android:textOff="The text for the component when it's not checked." 
     android:textOn="The text for the component when it's checked." 
     android:background="@drawable/offbuttonbg" 
     android:textAppearance="@style/SwitchTextAppearance" 
     android:thumb="@drawable/switchselector" /> 

si riferiscono sempre alla Switch Documentation se avete bisogno di maggiori informazioni.

+0

l'utente vuole nascondere il testo – Fahim

+0

Sono d'accordo che è per questo che la soluzione di impostare un testoOff e textOn funzionerà per questo caso, anche guardando il tuo suggerisci lo stesso, solo che solo per XML, ho dato entrambe le forme nel codice e XML, Nessun motivo per votare qui. – Nullpoint

Problemi correlati