0

我想在我的应用程序中实现一个 Switch 小部件,并且该功能运行良好。我对开关的问题是拇指上的关闭文本(“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>

我认为代码本身没有问题。我在 Activity 代码中所做的只是找到 Switch 视图来修改 setOnCheckedChangeListener 方法。

4

1 回答 1

0

android:textSize您可以尝试Switch像这样设置标签:

    <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"/>

Switchextends CompoundButton,extends Button,extends TextView,使这成为可能。您还可以尝试setTextSize()在代码上使用方法以编程方式设置文本大小。

于 2016-02-17T06:11:44.000 回答