Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android中带有文本跟踪的自定义开关_Java_Android_Xml_Uiswitch - Fatal编程技术网

Java Android中带有文本跟踪的自定义开关

Java Android中带有文本跟踪的自定义开关,java,android,xml,uiswitch,Java,Android,Xml,Uiswitch,我有一个自定义开关。我希望文本(开/关)位于曲目中,而不是拇指中 我正在考虑设置一个可绘制文本的选择器,并将其设置为开关的轨迹。但我不能在形状中设置文本。你知道我该怎么做吗 我还想在音轨上添加一些填充物,我不想让拇指碰到音轨。 这就是我想要的样子: 这是我的轨迹的形状: <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:visible="t

我有一个自定义开关。我希望文本(开/关)位于曲目中,而不是拇指中

我正在考虑设置一个可绘制文本的选择器,并将其设置为开关的轨迹。但我不能在形状中设置文本。你知道我该怎么做吗

我还想在音轨上添加一些填充物,我不想让拇指碰到音轨。 这就是我想要的样子:

这是我的轨迹的形状:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:visible="true"
android:useLevel="false">
<corners
    android:radius="20dp" />
<size
    android:width="48dp"
    android:height="21dp" />
<stroke
    android:color="#bfbfbf"
    android:width="6dp"/>


关闭屏幕截图

打开屏幕截图

打开图像

<android.support.v7.widget.SwitchCompat
    android:id="@+id/switch_compat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    app:track="@drawable/switch_on_off"
    android:thumb="@drawable/on_switch_active"/>

关闭图像

<android.support.v7.widget.SwitchCompat
    android:id="@+id/switch_compat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    app:track="@drawable/switch_on_off"
    android:thumb="@drawable/on_switch_active"/>

拇指图像

<android.support.v7.widget.SwitchCompat
    android:id="@+id/switch_compat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    app:track="@drawable/switch_on_off"
    android:thumb="@drawable/on_switch_active"/>

打开/关闭.xml

    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/on_switch"/>
    <item android:state_checked="false" android:drawable="@drawable/off_switch"/>
    <item android:drawable="@drawable/off_switch"/>
</selector>

xml代码

<android.support.v7.widget.SwitchCompat
    android:id="@+id/switch_compat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    app:track="@drawable/switch_on_off"
    android:thumb="@drawable/on_switch_active"/>


尝试上面的代码,如果发现任何错误,请告诉我。…

这是可能的,但我没有用于我的设计的特定图像。我使设计无需文字即可绘制。所有我需要的是添加文本。好吧,好吧,设置一个跟踪文本是不可能的,请参阅此链接,可能它可以整理您的查询:-我接受这个答案,因为它是迄今为止最好的