Please refer to my project at: https://github.com/paulpv/ToolbarSwitch
I am working on a simple custom layout for the Android Toolbar (aka: new ActionBar). This simp
I was following your code to add Switch to my action bar and I was able to solve your problem with the "jumping text" by setting the width of the Switch to wrap_content like this:
<Switch xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/action_switch"
android:text="@string/action_switch"
android:switchPadding="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
I gave up trying to use the built in Text field of a Switch or SwitchCompat control. I ended up providing a layout with a separate TextView field:
layout/toolbar_switch.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/action_switch_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingEnd="10dp"
android:paddingRight="10dp"
android:text="Switch"
android:textAllCaps="true"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/action_switch_control"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>