我正在使用下面的代码使用XML在Android中创建一个Material 3 Switch,它比普通的Switch大得多.有没有办法把它弄小一点?

<com.google.android.material.materialswitch.MaterialSwitch   
   android:id="@+id/biometrics_switch"   
   style="@style/Widget.Material3.CompoundButton.MaterialSwitch"   
   android:layout_width="wrap_content"   
   android:layout_height="wrap_content"   
   app:layout_constraintEnd_toEndOf="parent"   
   app:layout_constraintTop_toTopOf="parent"   
   app:switchPadding="@dimen/_10sdp" android:minHeight="@dimen/_10sdp" 
   app:thumbTint="@color/white" app:trackTint="@color/neutral_800" />

推荐答案

在material 中,switch 宽度和高度影响switch 的可点击区域 您应该使用scaleXscaleY来更改它的大小. 此外,在Jetpack Compose中,您应该使用Modifier.scale()

以下是它的示例代码:

<com.google.android.material.materialswitch.MaterialSwitch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="0.8"
android:scaleY="0.8"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

Android相关问答推荐

致命异常:java.lang. SecureExcellent::用户10021和当前进程都没有android. permissions.Change_WIFI_STATE

未解析的引用:背景 colored颜色

编写视觉转型

CameraX与jetpack组成屏幕逻辑

AdMob:MobileAds. initialize()—java. lang. xml对于某些设备不能强制转换为java. lang. String""

如何在Jetpack composeH中创建具有弯曲末端的六边形形状

如何消除脚手架和顶杆(material 3)更改 colored颜色 时的延迟?

Android v31 及更低版本中 ImageView 中的圆角

Play store 的 Play 完整性与 Firebase 应用判断 Play 完整性

弹出导航堆栈后,Compose 无法访问 Hilt View Model

Material 3的MaterialSwitch默认大小太大了?如何使它变小?

如何在Android Studio中禁用文件中的Github用户名引用?

如何避免多次调用 Jetpack Compose 的 onClick 回调

在 Material 3 TopAppBar 代码的哪个位置定义了填充?

AirDroid Business 如何能够从屏幕截图中排除覆盖?

Jetpack Compose 惰性列在单个项目更新时重新组合所有项目

从活动共享视图模型以使用 hilt 组合函数

如何在 compose 中使用 BottomSheetScaffold 为底页设置半展开高度?

如何对齐文本和图标可组合,以便即使在文本溢出后它们也能保持在一起?

运行一次 kotlin 流,但在下游收到两次