android - SwitchPreference 点击开关不会触发监听器
问题描述
我正在使用 SwitchPreference 但似乎只有单击首选项视图(行)才会触发首选项单击侦听器或首选项更改侦听器。单击开关本身后,即使开关状态发生变化,也不会调用侦听器。
对此有什么可做的吗?
编辑:我想通了。这是我的听众:
switchPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
//not called when clicking preference itself
return true;
}
});
这是我的 SwitchPreference:
<SwitchPreference
android:key="@string/key_email_messages"
android:layout="@layout/prefs_switch"
android:title="@string/title_email_messages" />
我正在使用自定义布局来更改首选项的字体大小。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewWrap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/prefs_row_padding">
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/pref_text_size" />
<Switch
android:id="@+id/switch_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true" />
</RelativeLayout>
我猜 SwitchPreference 找不到具有该 ID 的开关。我应该使用什么ID?
解决方案
推荐阅读
- laravel-5.8 - 重定向回job_seeker.register
- homebrew - 使用 brew 安装 Buck 尝试访问无效的 url 并抛出 404
- math - 如何获得由许多三角形组成的网格表面(或平面)的 4 个角?
- python - 找到图像的中心来定义一个 hitbox
- python - 关于 np.nonzero(arr)[0] 中尾随 [0] 的作用的问题
- linux-kernel - filename_lookup.part.64 vs filename_lookup 符号
- python - 将 NumPy 数据流式传输到 Tensorflow
- javascript - 自定义钩子错误:只能在函数组件的主体内部调用钩子
- r - 将两个量化列绘制到一个 geom_col 图中
- nuxt.js - 如何从 nuxt 插件发出事件?