- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试制作一个 Android 设置屏幕,其中包含一些 SeekBarPreferences,以选择从 0 到 10 的三个数字。但是,我的 OnPreferenceChanged 代码没有被调用。我的设置 Activity 代码:
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SeekBarPreference;
public class AdvancedSettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings, new AdvancedSettingsFragment())
.commit();
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
}
public static class AdvancedSettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.advanced_preferences, rootKey);
final SharedPreferences prefs=getContext().getSharedPreferences("gameSettings",0);
final SharedPreferences.Editor prefsedit=prefs.edit();
SeekBarPreference red=findPreference("redseekbar");
SeekBarPreference green=findPreference("greenseekbar");
SeekBarPreference blue=findPreference("blueseekbar");
red.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
prefsedit.putInt("red",(int)newValue);
prefsedit.apply();
Toast.makeText(getContext(),newValue+"",Toast.LENGTH_LONG);
return true;
}
});
green.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
prefsedit.putInt("green",(int)newValue);
prefsedit.apply();
Toast.makeText(getContext(),newValue+"",Toast.LENGTH_LONG);
return true;
}
});
blue.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
prefsedit.putInt("blue",(int)newValue);
prefsedit.apply();
Toast.makeText(getContext(),newValue+"",Toast.LENGTH_LONG);
return true;
}
});
}
}
}
我的偏好布局代码:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<SeekBarPreference
app:key="redseekbar"
app:title="Red"
app:summary="The red change value"
android:max="10"
app:defaultValue="0"
app:showSeekBarValue="true"/>
<SeekBarPreference
app:key="greenseekbar"
app:title="Green"
app:summary="The green change value"
android:max="10"
app:defaultValue="0"
app:showSeekBarValue="true"/>
<SeekBarPreference
app:key="blueseekbar"
app:title="Blue"
app:summary="The blue change value"
android:max="10"
app:defaultValue="0"
app:showSeekBarValue="true"/>
</PreferenceScreen>
我应该如何从seekbarpreference中获取类似onpreferencechanged的事件?(我正在使用 v7 支持库,并且不能切换/添加新支持库)
最佳答案
好吧,我不小心忘记在我的 Toast 上调用 .show() 。另外,我没有正确配置它进行测试。
关于java - 如何使用 androidx 从 SeekBarPreference 获取 OnPreferenceChanged 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56545141/
我目前正在尝试使用 http://android-journey.blogspot.com/2010/01/for-almost-any-application-we-need-to.html 实现
我在类中实现 SeekBarPreference 时遇到问题。 https://developer.android.com/reference/android/support/v7/preferenc
我只想在我的项目中包含一个只有 3 个值的 SeekBarPreference(紧急级别:低-中-高) 这可以在经典的 SeekBar 上轻松完成(请参见下面的示例),但我不知道如何将其包含在首选项中
SeekBarPreference 是怎么回事?让我展开... 如果我在 PreferenceScreen xml 中放置一个 SeekBarPreference,它可以正常工作(我可以在手机和模拟器
如何使用 SeekBarPreference 显示搜索栏值? 最佳答案 使用 JetPack,我可以简单地将以下属性添加到 SeekBarPreference XML 元素。 app:
我正在尝试将 SeekBarPreference 实现到我的偏好 XML 中。我曾尝试使用 MrBIMC seekbar ( https://github.com/MrBIMC/MaterialSee
您好,我想知道如何在扩展 Preference 的类中使用以下方法 findViewById(int id) ,该类定义了一个名为 setProgress(int) 的方法Progress) ,它使用
我在显示的 XML 文件中有一个 SeekBarPreference(并且 slider 有效),但是在我单击 OK 按钮后,该值似乎就消失了。 这是我的 XML 文件...
我正在使用 holoeverywhere 库,当我启动 ActivityPreference 时出现此错误: 06-22 22:54:23.425: E/AndroidRuntime(11853):
看完Material Design的设置部分可用here ,我遇到了以下屏幕截图: 显示的 3 个第一个首选项是搜索栏,但我找不到任何相关信息,即使在支持库中也是如此。 我是不是遗漏了什么,或者 Go
我在互联网上找到了这段代码,我想我会试一试。我把它放在我的偏好中,它完全符合我想要的方式,但我唯一的问题是我无法获得 SeekBar 的值。 这是我根据自己的喜好使用的代码链接: http://and
我正在尝试根据 docs 实现 androidx SeekBarPreference我也许可以在我的 xml 中使用 setMax 属性,但这样做时出现以下错误: 在 xml 中: 错误: root
我已经准备好了a simple test project对于我在 GitHub 上的问题。 在我的项目中有一个自定义内联 SeekBarPreference ,它大部分工作正常(当拖动搜索栏时它的摘要
我的 preferences.xml 中有以下首选项: 问题是这会呈现 Marglins 与 SwitchPreference 的标题非常不同的样式: 是否可以在我的 styles.xml 中添
首先,我是 Xamarin 和 Android 编程的新手。我已经创建了一个 SeekbarPreference,但是它们的某些布局无法正确显示。该值正在从框中掉落(见图)。 我的 styles.xm
我一直在尝试制作一个 Android 设置屏幕,其中包含一些 SeekBarPreferences,以选择从 0 到 10 的三个数字。但是,我的 OnPreferenceChanged 代码没有被调
我正在尝试从我的应用程序设置 (preferences.xml) 的布局中检索 SeekBarPreference。但是,当我尝试将 findPreference("font_size") 转换为 S
我是一名优秀的程序员,十分优秀!