2013-09-26 6 views
6

Android по умолчанию Switch имеют текст, а затем Switch on/off. Я ожидаю Switch вкл./Выкл., А затем текст. Не используйте другие виджетов, такие как TextView. Как установить Switch правый текст.Как сменить текст в правой части андроида?

+0

Используйте атрибут xml как android: textOn и android: textOff в вашем xml. –

+1

@JiteshDalsaniya по умолчанию переключатель имеют переключатель текст левой стороне и переключатель имеют правую сторону. Я ожидаю, что вы перейдете влево и переключите текст вправо. Можете ли вы очистить сейчас? что ожидается –

ответ

-2

я был в состоянии достигнуть взгляда я хотел с комбинацией:

  • ширина (120dp)

  • обивка (75dp)

  • и switchpadding (-90dp)

enter image description here

8

enter image description here

Заверните его в другую раскладку, без текстового значения и добавить TextView. увидеть мой код:

<LinearLayout 
     android:layout_width="match_parent" 
     android:orientation="horizontal" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp" 
     android:layout_height="wrap_content"> 
      <Switch 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/reminder" /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:text="Meeting Reminders" 
       android:layout_height="wrap_content" /> 
    </LinearLayout> 
+1

Отлично работает, но как реализовать, когда его нажимают на «напоминания собрания», чтобы переключить управление «Switch», без кодовой логики в активности? Например, 'for =" @ id/reminder "' – mihkov

2

Добавьте этот код на Xml файла:

  <Switch 
       android:id="@+id/simpleSwitch" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentRight="true" 

       android:layout_marginEnd="15dp" 
       android:layout_marginRight="15dp" 
       android:layout_marginTop="5dp" 
       android:checked="false" 
       android:textColor="@color/black" 
       android:textOff="@string/no" 
       android:textOn="@string/yes" 
       android:theme="@style/SCBSwitch" /> 

      <TextView 
       android:id="@+id/switchBtn_txtView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginEnd="5dp" 
       android:layout_marginRight="5dp" 
       android:layout_marginTop="10dp" 
       android:layout_toLeftOf="@+id/simpleSwitch" 
       android:gravity="center_horizontal" /> 

В деятельности или фрагмент:

Switch simpleSwitchBtn = (Switch) findViewById(R.id.simpleSwitch); 
     final TextView switchBtn_txtView = (TextView) findViewById(R.id.switchBtn_txtView); 


     simpleSwitchBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
       if(isChecked){ 
        switchBtn_txtView.setText("Yes"); 
       } 
       else { 
        switchBtn_txtView.setText("No"); 
       } 
      } 
     }); 

Я думаю, что его ПОЛЕЗНЫЕ к вам .... Спасибо

Смежные вопросы