Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.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
Android 具有自己布局的CheckBoxPreference_Android_Android Preferences_Checkboxpreference - Fatal编程技术网

Android 具有自己布局的CheckBoxPreference

Android 具有自己布局的CheckBoxPreference,android,android-preferences,checkboxpreference,Android,Android Preferences,Checkboxpreference,我有带有一些首选项复选框的首选项屏幕。我想更改标题和摘要的textColor和textSize,以及选中和取消选中复选框的图像。因此,我使用android:layout来更改此属性 我的ChceckBoxPreference: <CheckBoxPreference android:layout="@layout/preference_checkbox" android:key="temp" android:title="@string/title" and

我有带有一些首选项复选框的首选项屏幕。我想更改标题和摘要的textColor和textSize,以及选中和取消选中复选框的图像。因此,我使用
android:layout
来更改此属性

我的ChceckBoxPreference:

<CheckBoxPreference
    android:layout="@layout/preference_checkbox"
    android:key="temp"
    android:title="@string/title"
    android:summary="@string/summary"
    android:defaultValue="true" 
/>
id为
@+android:id/Title
的标题和id为
@+android:id/summary
的摘要显示的值正确。但是,尽管有默认值和id
@+android:id/checkbox
,该复选框仍无法正常工作。它没有显示正确的值,我无法更改保留在首选项中的值。 不使用任何布局,我可以在整个CheckBoxPreference中通过触摸更改checkbox的值。但现在(在我的布局中),我只能通过触摸这个复选框来更改复选框的值。
如何使用所有功能正确布局CheckBoxPreference?

尝试将其作为preference\u checkbox.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="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical" android:paddingRight="?android:attr/scrollbarSize">

<RelativeLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:layout_marginLeft="15dip"
    android:layout_marginRight="6dip" android:layout_marginTop="6dip"
    android:layout_marginBottom="6dip" android:layout_weight="1">

    <TextView android:id="@+android:id/title"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:singleLine="true" android:textAppearance="?android:attr/textAppearanceLarge"
        android:ellipsize="marquee" android:fadingEdge="horizontal"
        android:textColor="#FF0000" />

    <TextView android:id="@+android:id/summary"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title"
        android:textAppearance="?android:attr/textAppearanceSmall"
        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:orientation="vertical" />

</LinearLayout>


请参见,为您的应用程序将clickable和focusable设置为falsecheckbox@devisnikOP讨论的是更改首选项后面的整个布局,您指出的解决方案只是关于CheckboxDevisonik的答案应该是正确的。这些设置是影响首选项值更改所必需的。此代码段的来源:(ashish添加了颜色自定义)@ashish您发布此答案已经有很长时间了,但我被困在某个地方。我的xml中出现了一个错误,表示“无法解析symbol@+android:id/title”。你能帮我找出同样的原因吗。。
<?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="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical" android:paddingRight="?android:attr/scrollbarSize">

<RelativeLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:layout_marginLeft="15dip"
    android:layout_marginRight="6dip" android:layout_marginTop="6dip"
    android:layout_marginBottom="6dip" android:layout_weight="1">

    <TextView android:id="@+android:id/title"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:singleLine="true" android:textAppearance="?android:attr/textAppearanceLarge"
        android:ellipsize="marquee" android:fadingEdge="horizontal"
        android:textColor="#FF0000" />

    <TextView android:id="@+android:id/summary"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title"
        android:textAppearance="?android:attr/textAppearanceSmall"
        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:orientation="vertical" />

</LinearLayout>