是否有任何方法可以在首选项 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/