2015-02-18 25 views
7

Android uygulamasında anahtar kullanıyorum Düğme düğmesinin metnini gizlemek için herhangi bir düğme var, API düzeyi 21 için bir seçenek gizlemek için (android: showText) ama çalıştırmam gerekiyor metin iki seçeneğiniz XML üzerinden kodu aracılığıyla birbirlerine sahipAndroid anahtarı için varsayılan metni gizle Düğme

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

boş dizgiyi textOff, textOn ..., belki ... en basit çözüm .... – Opiatefuchs

+0

Kabul ediyorum, aşağıdaki örnek yanıtı inceleyin. – Nullpoint

+0

Evet, çok aptalca bir soru var, yine de hızlı cevabınız için teşekkürler – Madhu

cevap

9

,: alt seviye cihazlarda aşağıda benim xml olduğunu.

Via Kod: Daha fazla bilgi gerekiyorsa eğer

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

Daima Switch Documentation bakın

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.

+0

cevabımla ilgili sorun nedir? – Fahim

0

kullanmak gizlemek için alt versiyonu için

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

kullanıcı, metni gizlemek istiyor – Fahim

+0

Bu yüzden bir metin atma ve metin ayarlama çözümünün bu durum için çalışacağına katılıyorum, aynı zamanda sizden de aynı şeyi öneriyorsunuz, sadece XML için, her iki formu da XML, Burada oy kullanmak için bir neden yok. – Nullpoint

İlgili konular