java - 是否可以将自定义组件添加到 Android 中的首选项 Activity 中?

标签 java android sharedpreferences preferenceactivity

是否有任何方法可以在首选项 Activity 中添加自定义组件以更改设置的值?

最佳答案

您可以添加扩展 android.app.Preference 的任何自定义组件

或者,如果它应该是一个 View - 创建一个布局,但您必须在 PreferenceScreen 的布局中包含一个带有 android.R.id.list 的 ListView

<RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/layout_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background_color" >

    <YourCustomComponentView
        android:id="@+id/view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"/>

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_below="@+id/view"
        android:layout_alignParentBottom="true"/>

</RelativeLayout>

只需在添加任何首选项之前 setContentView() 即可。

关于java - 是否可以将自定义组件添加到 Android 中的首选项 Activity 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14777181/

相关文章:

尝试读取 .xlsx excel 文件时出现 java.lang.NoSuchMethodError

Android In App Billing 仅在 Samsung tab 10.1 中崩溃

android - View 拖放更新时出现 stackoverflow 错误

java - Android MainActivity 打印/将值转换为 0/null?

java - 如何使用共享首选项来更改语言

java - 将固定大小的 JPanel 添加到 jScrollPane

java - 在 Java 中将 UTF32 转换为 UTF16

java - 在Android中通过sharedPreferences在类之间传递值

java - 在测试类中模拟私有(private)静态最终变量

所有膨胀 View 的 Android onClickListener