- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
PreferenceScreen
中的开关具有很好的波纹效果,可以覆盖整个宽度。我怎样才能在 PreferenceScreen
(在正常布局中)之外的 SwitchMaterial
开关上获得这种链式 react ?
最佳答案
接触 ViewGroup,无论是直接接触 ViewGroup 还是从 ViewGroup 流向子流并返回子流。我找到 this post及其相关的 Stack Overflow 答案有助于理解触摸事件。
要获得 PreferenceScreen 涟漪效果,请将布局与开关的父布局设置为可点击且可聚焦,并带有涟漪背景。
无论是直接触摸开关还是 ViewGroup,我们都需要相同的响应。开关有自己的响应式背景,因此开关的背景设置为 @null
,因此它不会在触摸事件中突出显示。如果需要突出显示,可以将其删除。
<LinearLayout
android:id="@+id/switchLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:padding="16dp">
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/switchWidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false" />
</LinearLayout>
由于父项正在捕获开关,因此开关不会收到点击事件,因此我们必须在单击 ViewGroup 时以编程方式单击开关:
val switchLayout = findViewById<ViewGroup>(R.id.switchLayout)
switchLayout.setOnClickListener {
findViewById<View>(R.id.switchWidget).performClick()
}
这一切将为我们提供以下内容:
关于android - 偏好开关对 SwitchMaterial 的链式 react ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70627176/
PreferenceScreen 中的开关具有很好的波纹效果,可以覆盖整个宽度。我怎样才能在 PreferenceScreen(在正常布局中)之外的 SwitchMaterial 开关上获得这种链式
我有一个这样的 Material 切换按钮: 这是风格: sans-serif-light--> bold--> @color/colorPrima
这两个对象( SwitchCompat 和 SwitchMaterial )有什么区别?我已经尝试过它们,并且在视觉上它们是相同的。 顺便说一句,他们为什么要删除 Switch类(class)?你知道
我是一名优秀的程序员,十分优秀!