我想在我的应用程序中实现一个切换窗口小部件,并且该功能工作得很好。开关的问题是拇指上的off文本("OFF")。"OFF“比拇指的大小更大。我想增加拇指的大小(或减少拇指文本),但由于某种奇怪的原因,我无法做到这两个。看起来是这样的:
开关的关闭状态

屏幕截图

下面是XML文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/gameSettingsContainer"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
tools:context="com.example.vb1115.multchoicequestion.LaunchScreen">
<LinearLayout
android:id="@+id/lessonModeSliderContainer"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<Switch
android:id="@+id/lessonModeToggleSlider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:showText="true"/>
</LinearLayout>
<ImageView
android:id="@+id/lessonModeAnimatedArrow"
android:src="@mipmap/green_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/lessonModeSliderContainer"/>
</RelativeLayout>我不认为代码本身有问题。我在我的活动代码中所做的一切就是查找切换视图来修改setOnCheckedChangeListener方法。
发布于 2016-02-17 14:11:44
您可以尝试在Switch标记上设置android:textSize,如下所示:
<Switch
android:id="@+id/lessonModeToggleSlider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textSize="text_size_here" <----- this line
android:showText="true"/>Switch类扩展了CompoundButton,后者扩展了Button,后者扩展了TextView,从而使这成为可能。您还可以尝试在代码中使用setTextSize()方法以编程方式设置文本大小。
https://stackoverflow.com/questions/35441529
复制相似问题