简体   繁体   English

是否可以在android的首选项活动中添加自定义组件?

[英]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 您可以添加任何扩展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 或者,如果它应该是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>

Just setContentView() it before adding any preference. 在添加任何首选项之前,只需setContentView()即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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