gpt4 book ai didi

android - 样式化 android.support.v7.preference.SeekBarPreference

转载 作者:行者123 更新时间:2023-11-29 01:08:58 26 4
gpt4 key购买 nike

首先,我是 Xamarin 和 Android 编程的新手。我已经创建了一个 SeekbarPreference,但是它们的某些布局无法正确显示。该值正在从框中掉落(见图)。

enter image description here

我的 styles.xml:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MyTheme" parent="MyTheme.Base">

</style>

<style name="MyTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#EC6A1E</item>
<item name="colorAccent">#EC6A1E</item>
<item name="toolbarStyle">@style/custom_toolbar</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material.Fix</item>
</style>

<style name="custom_toolbar" parent="@style/Widget.AppCompat.Toolbar">
<item name="titleTextColor">#FFFFFF</item>
</style>

<style name="PreferenceThemeOverlay.v14.Material.Fix" parent="PreferenceThemeOverlay.v14.Material">
<item name="seekBarPreferenceStyle">@style/Preference.SeekBarPreference.Fix</item>
</style>

<style name="Preference.SeekBarPreference.Fix">
</style>
</resources>

这是我的settings.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.SeekBarPreference
android:id="@+id/preference_range_seek_bar"
android:layout_height="wrap_content"
android:key="range"
android:title="Range"
android:summary="Here you can set the range of your location"
android:max="10000"
android:defaultValue="500" />
<android.support.v7.preference.SeekBarPreference
android:key="favRange"
android:title="Favorite Range"
android:summary="Here you can set the range of your Favorite location"
android:max="10000"
android:defaultValue="500" />
<android.support.v7.preference.Preference android:title="Title" android:summary="This is the summary">
</android.support.v7.preference.Preference>

</android.support.v7.preference.PreferenceScreen>

我不明白的是如何找到可以在 SeekBarPreference 上使用哪些 xml 属性来解决此问题。当我查看 Google 文档时,找不到关于此 SeekBarPreference 的 xml 属性的描述。

我知道我的主题很模糊,因为我玩了很多。但是当我让它工作时,我会对其进行调整。

希望有人能帮助我,或者举个例子..

最佳答案

遇到了同样的问题。下面是解决方案,在运行 API 25 的模拟器上进行测试:

第 1 步,创建一个扩展 SeekBarPreference 的新类

public class CustomSeekBarPreference extends SeekBarPreference {
private TextView mSeekBarValueTextView;

public CustomSeekBarPreference(Context context,
AttributeSet attributeSet,
int i, int i1) {
super(context, attributeSet, i, i1);
}

public CustomSeekBarPreference(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
}

public CustomSeekBarPreference(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}

public CustomSeekBarPreference(Context context) {
super(context);
}

@Override
public void onBindViewHolder(PreferenceViewHolder preferenceViewHolder) {
super.onBindViewHolder(preferenceViewHolder);
mSeekBarValueTextView = (TextView) preferenceViewHolder.findViewById(android.support.v7.preference.R.id.seekbar_value);
if (mSeekBarValueTextView != null) {
LayoutParams layoutParams = mSeekBarValueTextView.getLayoutParams();
layoutParams.height = LayoutParams.WRAP_CONTENT;
mSeekBarValueTextView.setLayoutParams(layoutParams);
}
}
}

在您的 preferences.xml 中,将 SeekBarPreference 类名替换为自定义类名。

<com.google.xxx.view.CustomSeekBarPreference
android:key="cacheLimit"
android:title="@string/setting_cache_limit_title"
android:dependency="enableCaching"
android:defaultValue="20"
android:max="40"/>

关于android - 样式化 android.support.v7.preference.SeekBarPreference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44706952/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com