Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 是否可以在android中向首选项活动添加自定义组件?_Java_Android_Sharedpreferences_Preferenceactivity - Fatal编程技术网

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

Java 是否可以在android中向首选项活动添加自定义组件?,java,android,sharedpreferences,preferenceactivity,Java,Android,Sharedpreferences,Preferenceactivity,有没有办法在首选项活动中添加自定义组件以更改设置值?您可以添加任何扩展的自定义组件 或者如果它应该是一个视图-创建一个布局,但是您必须在首选项屏幕的布局中包含一个带有android.R.id.list的ListView <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools

有没有办法在首选项活动中添加自定义组件以更改设置值?

您可以添加任何扩展的自定义组件

或者如果它应该是一个视图-创建一个布局,但是您必须在首选项屏幕的布局中包含一个带有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>
在添加任何首选项之前,只需设置ContentView即可