Android中的文本跟踪自定义开关
问题描述:
我有一个自定义开关。我希望文字(开/关)在曲目中,而不是在大拇指中。Android中的文本跟踪自定义开关
我在考虑设置一个选择器,其中的文本是可绘制的,并将其设置为开关的轨迹。但是我无法设置文字的形状。任何想法我可以做到这一点?
我也想添加一些填充的轨道,我不想让拇指触摸轨道。 这是怎么样的我多么希望它看起来:
这是我的轨迹的形状:
<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"/>
答
关掉屏幕截图
上截图开关
接通图像
切断图像
拇指图像
switch_on_off.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"/>
试试上面的代码,让我知道如果你发现任何错误.....
这是可能的,但我没有具体的图像为我的设计。我将设计绘制成没有文字。我需要的只是添加文本。 –
那么AFAIK,设置文本轨道是不可能的,请参考此链接,可能是它可以整理你的查询: - http://stackoverflow.com/questions/34765660/custom-android-switch-track-animation – Bhavnik