to top
Android APIs
 

switches.xml

← Back

The file containing the source code shown below is located in the corresponding directory in <sdk>/samples/android-<version>/...

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 The Android开源工程

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
  -->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    <LinearLayout
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="wrap_content">

        <Switch android:text="Standard switch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="32dip" />

        <Switch android:text="Default is on"
                android:checked="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="32dip" />

        <Switch android:id="@+id/monitored_switch"
                android:text="Monitored switch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="32dip" />

        <Switch android:text="Customized text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textOn="YES"
                android:textOff="NO"
                android:layout_marginBottom="32dip" />

        <Switch android:text="This is an example of a switch with a lot of text in it. It may end up wrapping to another line. The switch will be pinned at the top."
                android:singleLine="false"
                android:layout_width="300dip"
                android:layout_height="wrap_content"
                android:gravity="top|left"
                android:layout_marginBottom="32dip" />

        <Switch android:text="This is an example of a switch with a lot of text in it. It may end up wrapping to another line. The switch will be vertically centered."
                android:singleLine="false"
                android:layout_width="300dip"
                android:layout_height="wrap_content"
                android:gravity="center_vertical|left"
                android:layout_marginBottom="32dip" />

        <Switch android:text="This is an example of a switch with a lot of text in it. It may end up wrapping to another line. The switch will be pinned at the bottom."
                android:singleLine="false"
                android:layout_width="300dip"
                android:layout_height="wrap_content"
                android:gravity="bottom|left"
                android:layout_marginBottom="32dip" />

        <Switch android:text="Switch with match_parent width"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="32dip" />

        <TextView android:text="Standalone switch below:"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />

        <Switch android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

    </LinearLayout>
</ScrollView>