【问题标题】:android switch thumb text cutoffandroid切换拇指文本截止
【发布时间】:2023-03-07 04:06:01
【问题描述】:

我想在我的应用程序中实现一个 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 方法。

【问题讨论】:

标签: android android-studio android-linearlayout android-relativelayout android-switch


【解决方案1】:

您可以尝试在您的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() 方法以编程方式设置文本大小。

【讨论】:

  • 我尝试了以下方法: XML: android:textSize="2.0sp" android:textSize="2dp" 代码:lessonModeToggle.setTextSize(2.0f);这三个都没有工作......
猜你喜欢
  • 1970-01-01
  • 2015-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多