自定义preference的使用

control_iconsize_preference_top.xml

<?xml version="1.0" encoding="utf-8"?>

<ImageView
    android:id="@android:id/icon"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_gravity="center"
    android:paddingLeft="16dp"
    />

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginEnd="18dp"
    android:layout_marginTop="1dp"
    android:layout_marginBottom="1dp"
    android:layout_weight="1">

    <TextView android:id="@android:id/title"
        android:layout_width="wrap_content"
        android:layout_height="34dp"
        android:textSize="17sp"
        android:gravity="center_vertical"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal" />

    <TextView 
        android:id="@android:id/summary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginStart="5dp"
        android:gravity="end"
        android:maxLines="1"
        android:ellipsize="end"
        android:layout_toEndOf="@android:id/title"
        android:layout_toStartOf="@id/iv_arrow_right"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="?android:attr/textColorSecondary"/>

<ImageView
    android:id="@+id/iv_arrow_right"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_centerVertical="true"
        android:layout_alignParentEnd="true"
        android:src="@drawable/ic_homepage_arrow_right"
        android:paddingLeft="16dp"/>

</RelativeLayout>

<!-- Preference should place its actual preference widget here. -->
<LinearLayout android:id="@android:id/widget_frame"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:paddingEnd="16dp"
    android:orientation="vertical" />

control_iconsize_preference_middle.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!-- Layout for a Preference in a PreferenceActivity. The
     Preference is able to place a specific widget for its particular
     type in the "widget_frame" layout. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:minHeight="58dp"
    android:gravity="center_vertical"
    android:paddingEnd="?android:attr/scrollbarSize"
    android:background="@drawable/card_style_middle" >

    <ImageView
        android:id="@android:id/icon"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_gravity="center"
        android:paddingLeft="16dp"
        />

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="18dp"
        android:layout_marginTop="1dp"
        android:layout_marginBottom="1dp"
        android:layout_weight="1">

        <TextView android:id="@android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="34dp"
            android:textSize="17sp"
            android:gravity="center_vertical"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal" />

	    <TextView android:id="@android:id/summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginStart="5dp"
            android:gravity="end"
            android:maxLines="1"
            android:ellipsize="end"
            android:layout_toEndOf="@android:id/title"
            android:layout_toStartOf="@id/iv_arrow_right"
            android:textAppearance="?android:attr/textAppearanceSmall"
	        android:textColor="?android:attr/textColorSecondary"/>

	    <ImageView
	        android:id="@+id/iv_arrow_right"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_centerVertical="true"
            android:layout_alignParentEnd="true"
            android:src="@drawable/ic_homepage_arrow_right"
            android:paddingLeft="16dp"/>

    </RelativeLayout>

    <!-- Preference should place its actual preference widget here. -->
    <LinearLayout android:id="@android:id/widget_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:paddingEnd="16dp"
        android:orientation="vertical" />

</LinearLayout>

control_iconsize_preference_bottom.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!-- Layout for a Preference in a PreferenceActivity. The
     Preference is able to place a specific widget for its particular
     type in the "widget_frame" layout. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:minHeight="58dp"
    android:gravity="center_vertical"
    android:paddingEnd="?android:attr/scrollbarSize"
    android:background="@drawable/card_style_bottom" >

    <ImageView
        android:id="@android:id/icon"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_gravity="center"
        android:paddingLeft="16dp"
        />

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="18dp"
        android:layout_marginTop="1dp"
        android:layout_marginBottom="1dp"
        android:layout_weight="1">

        <TextView android:id="@android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="34dp"
            android:textSize="17sp"
            android:gravity="center_vertical"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal" />

        <TextView android:id="@android:id/summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginStart="5dp"
            android:gravity="end"
            android:maxLines="1"
            android:ellipsize="end"
            android:layout_toEndOf="@android:id/title"
            android:layout_toStartOf="@id/iv_arrow_right"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"/>

        <ImageView
            android:id="@+id/iv_arrow_right"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_centerVertical="true"
            android:layout_alignParentEnd="true"
            android:src="@drawable/ic_homepage_arrow_right"
            android:paddingLeft="16dp"/>

    </RelativeLayout>

    <!-- Preference should place its actual preference widget here. -->
    <LinearLayout android:id="@android:id/widget_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:paddingEnd="16dp"
        android:orientation="vertical" />

</LinearLayout>

control_iconsize_preference_airplane.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!-- Layout for a Preference in a PreferenceActivity. The
     Preference is able to place a specific widget for its particular
     type in the "widget_frame" layout. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:minHeight="58dp"
    android:gravity="center_vertical"
    android:paddingEnd="?android:attr/scrollbarSize"
    android:background="@drawable/card_style_top" >

    <ImageView
        android:id="@android:id/icon"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_gravity="center"
        android:paddingLeft="16dp"
        />

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="6dp"
        android:layout_marginTop="1dp"
        android:layout_marginBottom="1dp"
        android:layout_weight="1">

        <TextView android:id="@android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="34dp"
            android:textSize="17sp"
            android:gravity="center_vertical"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal" />

        <TextView android:id="@android:id/summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@android:id/title"
            android:layout_alignStart="@android:id/title"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"
            android:maxLines="4" />

    </RelativeLayout>

    <!-- Preference should place its actual preference widget here. -->
    <LinearLayout android:id="@android:id/widget_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:paddingEnd="16dp"
        android:orientation="vertical" />

</LinearLayout>

control_iconsize_preference_no_arrow_top.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!-- Layout for a Preference in a PreferenceActivity. The
     Preference is able to place a specific widget for its particular
     type in the "widget_frame" layout. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:minHeight="58dp"
    android:gravity="center_vertical"
    android:paddingEnd="?android:attr/scrollbarSize"
    android:background="@drawable/card_style_top" >

    <ImageView
        android:id="@android:id/icon"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_gravity="center"
	android:paddingLeft="0dp"
	android:visibility="gone"
        />

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="18dp"
        android:layout_marginTop="1dp"
        android:layout_marginBottom="1dp"
	android:layout_weight="1"
	android:paddingStart="16dp">

        <TextView android:id="@android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="34dp"
            android:textSize="17sp"
            android:gravity="center_vertical"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal" />

        <TextView android:id="@android:id/summary"
            android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:layout_centerVertical="true"
	    android:layout_marginStart="5dp"
	    android:gravity="end"
	    android:maxLines="1"
            android:ellipsize="end"
	    android:layout_alignParentEnd="true"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"/>

	<com.starkylin.settings.widget.tick.TickView
            android:id="@+id/tick_view"
            android:layout_width="28dp"
            android:layout_height="28dp"
            android:layout_marginStart="5dp"
	    android:layout_alignParentEnd="true"
	    android:layout_centerVertical="true"
            android:visibility="gone"
            app:check_base_color="#00FFB7"
            app:check_tick_color="#00FFB7"
	    app:rate="normal" />

    </RelativeLayout>

    <!-- Preference should place its actual preference widget here. -->
    <LinearLayout android:id="@android:id/widget_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:paddingEnd="16dp"
        android:orientation="vertical" />

</LinearLayout>

control_iconsize_preference_no_arrow_middle.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!-- Layout for a Preference in a PreferenceActivity. The
     Preference is able to place a specific widget for its particular
     type in the "widget_frame" layout. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:minHeight="58dp"
    android:gravity="center_vertical"
    android:paddingEnd="?android:attr/scrollbarSize"
    android:background="@drawable/card_style_middle" >

    <ImageView
        android:id="@android:id/icon"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_gravity="center"
	android:paddingLeft="0dp"
	android:visibility="gone"
        />

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="18dp"
        android:layout_marginTop="1dp"
        android:layout_marginBottom="1dp"
	android:layout_weight="1"
	android:paddingStart="16dp">

        <TextView android:id="@android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="34dp"
            android:textSize="17sp"
            android:gravity="center_vertical"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal" />

        <TextView android:id="@android:id/summary"
            android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:layout_centerVertical="true"
	    android:layout_marginStart="5dp"
	    android:gravity="end"
	    android:maxLines="1"
            android:ellipsize="end"
	    android:layout_alignParentEnd="true"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"/>

	<com.starkylin.settings.widget.tick.TickView
            android:id="@+id/tick_view"
            android:layout_width="28dp"
            android:layout_height="28dp"
            android:layout_marginStart="5dp"
	    android:layout_alignParentEnd="true"
	    android:layout_centerVertical="true"
            android:visibility="gone"
            app:check_base_color="#00FFB7"
            app:check_tick_color="#00FFB7"
            app:rate="normal" />
    </RelativeLayout>

    <!-- Preference should place its actual preference widget here. -->
    <LinearLayout android:id="@android:id/widget_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:paddingEnd="16dp"
        android:orientation="vertical" />

</LinearLayout>

control_iconsize_preference_no_arrow_bottom.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!-- Layout for a Preference in a PreferenceActivity. The
     Preference is able to place a specific widget for its particular
     type in the "widget_frame" layout. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:minHeight="58dp"
    android:gravity="center_vertical"
    android:paddingEnd="?android:attr/scrollbarSize"
    android:background="@drawable/card_style_bottom" >

    <ImageView
        android:id="@android:id/icon"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_gravity="center"
	android:paddingLeft="0dp"
	android:visibility="gone"
        />

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="18dp"
        android:layout_marginTop="1dp"
        android:layout_marginBottom="1dp"
	android:layout_weight="1"
	android:paddingStart="16dp">

        <TextView android:id="@android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="34dp"
            android:textSize="17sp"
            android:gravity="center_vertical"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal" />

        <TextView android:id="@android:id/summary"
            android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:layout_centerVertical="true"
	    android:layout_marginStart="5dp"
	    android:gravity="end"
	    android:maxLines="1"
            android:ellipsize="end"
	    android:layout_alignParentEnd="true"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"/>

	<com.starkylin.settings.widget.tick.TickView
            android:id="@+id/tick_view"
            android:layout_width="28dp"
            android:layout_height="28dp"
            android:layout_marginStart="5dp"
	    android:layout_alignParentEnd="true"
	    android:layout_centerVertical="true"
            android:visibility="gone"
            app:check_base_color="#00FFB7"
            app:check_tick_color="#00FFB7"
            app:rate="normal" />
    </RelativeLayout>

    <!-- Preference should place its actual preference widget here. -->
    <LinearLayout android:id="@android:id/widget_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:paddingEnd="16dp"
        android:orientation="vertical" />

</LinearLayout>

control_iconsize_preference_no_arrow_transparent.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!-- Layout for a Preference in a PreferenceActivity. The
     Preference is able to place a specific widget for its particular
     type in the "widget_frame" layout. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:minHeight="58dp"
    android:gravity="center_vertical"
    android:background="@color/transparent"
    android:paddingEnd="?android:attr/scrollbarSize" >

    <ImageView
        android:id="@android:id/icon"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_gravity="center"
	android:paddingLeft="0dp"
	android:visibility="gone"
        />

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="18dp"
        android:layout_marginTop="1dp"
        android:layout_marginBottom="1dp"
	android:layout_weight="1"
	android:paddingStart="16dp">

        <TextView android:id="@android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="34dp"
            android:textSize="17sp"
            android:gravity="center_vertical"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal" />

        <TextView android:id="@android:id/summary"
            android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:layout_centerVertical="true"
	    android:layout_marginStart="5dp"
	    android:gravity="end"
	    android:maxLines="1"
            android:ellipsize="end"
	    android:layout_alignParentEnd="true"
            android:textAppearance="?android:attr/textAppearanceSmall"
	    android:textColor="?android:attr/textColorSecondary"/>

	<com.starkylin.settings.widget.tick.TickView
            android:id="@+id/tick_view"
            android:layout_width="28dp"
	    android:layout_height="28dp"
	    android:layout_marginStart="5dp"
	    android:layout_alignParentEnd="true"
	    android:layout_centerVertical="true"
	    android:visibility="gone"
            app:check_base_color="#00FFB7"
            app:check_tick_color="#00FFB7"
            app:rate="normal" />

    </RelativeLayout>

    <!-- Preference should place its actual preference widget here. -->
    <LinearLayout android:id="@android:id/widget_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:paddingEnd="16dp"
        android:orientation="vertical" />

</LinearLayout>

control_iconsize_preference_satellite.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!-- Layout for a Preference in a PreferenceActivity. The
     Preference is able to place a specific widget for its particular
     type in the "widget_frame" layout. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="58dp"
    android:gravity="center_vertical"
    android:paddingEnd="?android:attr/scrollbarSize">

    <ImageView
        android:id="@+id/icon"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_gravity="center"
	android:paddingLeft="16dp"
	android:src="@drawable/starkylin_voice_communication"
        />

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="16dp"
        android:layout_marginTop="1dp"
        android:layout_marginBottom="1dp"
        android:layout_weight="1">

        <TextView android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="34dp"
            android:textSize="17sp"
            android:gravity="center_vertical"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal" />

        <TextView android:id="@+id/summary"
            android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:layout_centerVertical="true"
	    android:layout_marginStart="5dp"
	    android:gravity="end"
	    android:maxLines="1"
            android:ellipsize="end"
	    android:layout_toEndOf="@id/title"
	    android:layout_toStartOf="@id/iv_arrow_right"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"/>

	<ImageView
	    android:id="@+id/iv_arrow_right"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_centerVertical="true"
	    android:layout_alignParentEnd="true"
	    android:src="@drawable/ic_homepage_arrow_right"
	    android:paddingLeft="16dp"/>

    </RelativeLayout>

</LinearLayout>

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
自定义Preference的布局,可以按照以下步骤操作: 1.创建一个XML布局文件,该文件应包含您希望在Preference中显示的UI元素。例如,如果您希望显示一个文本框和一个开关,可以创建一个包含这些元素的布局文件。 2.在Preference类的子类中,覆盖onCreateView()方法。在这个方法中,使用LayoutInflater加载您的布局文件。 3.在onCreateView()方法中,使用findViewByld()方法获取您的UI元素的引用,并设置它们的值和行为(例如,将文本框的文本设置为Preference存储的值)。 4.如果您希望在用户更改Preference值时更新UI元素,请覆盖onPreferenceChange()方法并在其中更新您的UI元素。 下面是一个示例代码: ```java public class MyPreference extends Preference { private EditText mEditText; private Switch mSwitch; public MyPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Override public View onCreateView(ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.my_preference_layout, parent, false); mEditText = (EditText) view.findViewById(R.id.edit_text); mSwitch = (Switch) view.findViewById(R.id.switch_button); mEditText.setText(getPersistedString("default value")); mSwitch.setChecked(getPersistedBoolean(false)); return view; } @Override public void onPreferenceChange(Preference preference, Object newValue) { if (preference == this) { mEditText.setText((String) newValue); mSwitch.setChecked((Boolean) newValue); } } } ``` 在这个例子中,我们创建了一个名为my_preference_layout.xml的布局文件,其中包含一个EditText和一个Switch。然后,我们在MyPreference类中覆盖了onCreateView()方法来加载这个布局文件,查找EditText和Switch元素,并设置它们的值和行为。我们还覆盖了onPreferenceChange()方法来更新UI元素,以反映Preference值的更改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值