android - 向 PreferenceActivity 添加 header

标签 android

所以我发现android PreferenceScreen 不是很友好。是否有一种半简单的方法可以在显示首选项之前将标题(比如图像)添加到首选项屏幕?我目前正在扩展 PreferenceActivity 类,但有人可以告诉我如何向标题添加线性布局吗?

谢谢

最佳答案

在我的应用程序中,我完全按照您的要求进行操作:

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    setContentView(R.layout.preferences_layout);
}

preferences_layout.xml 文件中:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">

<ImageView
    android:id="@+id/myCustomImageView"
    android:src="@drawable/xmas"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
/>
<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:layout_below="@+id/myCustomImageView"
/>

</RelativeLayout>

注意在xml中ListView设置的android:id 现在,您可以控制首选项屏幕的布局,只要您使用内置首选项,就可以使用首选项的默认样式。

关于android - 向 PreferenceActivity 添加 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5443491/

相关文章:

java - Android Studio 中的错误 : Failed to resolve: com. mikepenz :aboutlibraries:6. 0.1

android - CheckedTextView 的中心文本和复选标记

java - 为多个平台开发

java - 使用带有 GridLayoutManager 的 RecyclerView 将动态按钮添加到手机和平板电脑的不同布局

Android 使用 JNI 而不使用静态变量

java - 使用 Appium 处理 Android 应用中的弹出窗口

android - 向 Gson 注册此类型的 InstanceCreator 可能会解决此问题

android - 更改 FloatingActionButton 的背景?

java - Places SDK 中的 APIException 9011 和 9010 错误

android - 带有动态 Edittext 的 RecyclerView