首页 > 解决方案 > Android Studio 在 XML 中将 Switch 添加到 textview 的左侧

问题描述

与使用 向 textview 左侧添加图标类似android:drawableleft="...",我想做类似的事情,除了switch在同一个 XML 文件中使用预定义的。我该怎么做?

标签: androidxml

解决方案


 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
            <Switch
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/switch" />
            <TextView
                android:layout_width="wrap_content"        
                android:layout_height="wrap_content" 
                android:text="Switch Text" />
    </LinearLayout>

如果是单选按钮或复选框,您总是可以使用类似这样的东西

android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"

推荐阅读