- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个扩展 Preference 的自定义类,我将它与 PreferenceActivity 结合使用。
当我尝试调整我的 Preference 正在使用的布局中的高度(使用静态 layout_height 或 wrap_content)时,它始终显示在 Preference Activity 中的统一高度单元格中 - 与所有“正常”的尺寸相同首选项默认为。
有没有办法用不同的 layout_height 呈现给定的偏好。
我查看了与首选项相关的 API 演示,但没有看到任何与我正在尝试做的相匹配的内容。
最佳答案
您可以在首选项中覆盖 getView(View, ViewGroup)
。然后将 new LayoutParams
发送到 getView()
。我尝试使用自定义的 CheckBoxPreference。效果很好。
import android.content.Context;
import android.preference.CheckBoxPreference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView.LayoutParams;
public class CustomCheckBoxPreference extends CheckBoxPreference {
public CustomCheckBoxPreference(final Context context, final AttributeSet attrs,
final int defStyle) {
super(context, attrs, defStyle);
}
public CustomCheckBoxPreference(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
public CustomCheckBoxPreference(final Context context) {
super(context);
}
@Override
public View getView(final View convertView, final ViewGroup parent) {
final View v = super.getView(convertView, parent);
final int height = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
final int width = 300;
final LayoutParams params = new LayoutParams(height, width);
v.setLayoutParams(params );
return v;
}
请注意为 View 使用正确的 LayoutParams,否则您可能会遇到类转换异常。
关于android - PreferenceActivity 中不同高度的偏好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8762996/
typedef unsigned char uChar; typedef signed char sChar; typedef unsigned short uShort; typedef signe
我正在编写一个 android 应用程序并想做一个 SettingsActivity。 我的问题是我的矢量可绘制对象不会使其颜色适应夜间或白天主题。 ic_palette_black_24dp.xml
我正在使用多语言闹钟 android 应用程序工作: 1 个 xml 文件 [alarm_settings.xml] 2 个 string.xml 文件 [英语和阿拉伯语] 问题是本地化没有以正确的方
我正在尝试创建一个 SettingsActivity 并使用扩展 PreferenceFragment 的 Fragment 来实现此目的。我的 Activity 正在显示,而首选项不是。 Setti
我知道在使用自动属性时,编译器会在屏幕后面创建自己的支持字段。然而,在我阅读以学习的许多程序中,我看到人们明确地写 private int _backingField; public int Prop
在写入事件日志时,我可以创建一个 EventLog 实例,将其作为成员变量保存,并在每次我想记录消息时对其调用 WriteEntry(string message)。 或者,我可以只调用静态版本:Ev
如何通过ListPreference值设置依赖? 最佳答案 正如 Snicolas 已经指出的那样,依赖 xml 功能仅检查 bool 状态(= 如果引用的键为真或在其中设置了值)。如果启用,您可
如果我使用 Preference API存储用户或系统偏好,它们在 Windows 和 Unix 上存储在哪里? 最佳答案 对于 Windows,systemRoot 和 userRoot 分别存储在
测试 android.preference.PreferenceActivity 时,我收到以下警告: warning: [deprecation] getFragmentManager() in A
在优先级Activity中我们可以使用这两个方法SetContentView(R.layout.main) 和 addXmlFromResources(R.xml.Preferences) 用于自定义
在我的 Android 应用程序中,我有一个偏好 Activity ,让用户可以覆盖应用程序的语言。为此,我在每个 Activity 的 onResume() 中调用此函数,然后重置内容 View :
在我的preferences.xml 中,我有一个这样的偏好元素: 我想分配 onClick 事件,所以如果用户点击它,我将能够打开新的 Intent 或浏览器。我尝试像使用按钮一样进行操作,但这似
这是我的PreferenceActivity(我的主要 Activity 的内部类) public static class TestSettings extends PreferenceActivi
对于 MVC Razor 中的简单标签,您更喜欢使用简单的 HTML 还是使用扩展方法例如 Male Or @Html.Label("male", "Male") 我觉得有时使用简单的 HTML
我有一个很奇怪的问题。当我在我的设置- Activity 中滚动时,一些复选框在不再显示时会发生变化。例如:我取消选中广告复选框,然后向下滚动,当复选框完全消失时,复选框会重置。只有当我取消选中默认值
我有一个带有 PreferenceActivity 的 Android 应用程序,其中一个首选项条目启动了我自己的 Activity 之一(“关于”屏幕)。该条目如下所示: 此外(这很重
实现“夜间主题”。我不知道如何更改 ListPreference 的背景颜色。 PreferenceActivity "day" theme PreferenceActivity night them
这个问题在这里已经有了答案: When to use ES6 class based React components vs. functional ES6 React components? (5
我在私有(private)模式下启动了 Firefox 并打开了 youtube。我看到的第一件事是根据我以前的 watch 推荐的视频。但是我没有登录,我处于私有(private)模式,为什么 yo
我试图在偏好 Activity 中展示广告,但它从未出现过。 Logcat 始终显示消息“没有足够的空间来显示广告!想要:,有:” 这就是我制作广告的方式。我对广告有自定义偏好 public clas
我是一名优秀的程序员,十分优秀!