简体   繁体   中英

Is it possible to add a custom component to a Preference Activity in android?

有什么方法可以在首选项活动中添加自定义组件以更改设置的值?

You can add any custom component that extends android.app.Preference

Or if it should be a View - create a layout, but you must include a ListView with android.R.id.list in your layout for the PreferenceScreen

<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>

Just setContentView() it before adding any preference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM