Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.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 安卓复选框首选颜色_Android_Checkbox_Colors_Preferenceactivity - Fatal编程技术网

Android 安卓复选框首选颜色

Android 安卓复选框首选颜色,android,checkbox,colors,preferenceactivity,Android,Checkbox,Colors,Preferenceactivity,如何更改CheckBoxPreference的复选框颜色?我无法指定主题属性。我也在清单中设置了主题,但它不是用强调色显示的,而是用默认颜色显示的 舱单: <activity android:name=".ui.activities.AppPreferencesActivity" android:theme="@style/PreferencesTheme"/> 风格: <style name="PreferencesTheme"> <item na

如何更改CheckBoxPreference的复选框颜色?我无法指定主题属性。我也在清单中设置了主题,但它不是用强调色显示的,而是用默认颜色显示的

舱单:

<activity android:name=".ui.activities.AppPreferencesActivity"
android:theme="@style/PreferencesTheme"/>

风格:

<style name="PreferencesTheme">
    <item name="colorAccent">#FF4081</item>
</style>

#FF4081

我错过什么了吗?提前感谢。

使用ColorPrimary而不是colorAccent

<item name="android:colorPrimary">#FF4081</item>
#FF4081

我解决了在mystyle.xml中指定所需颜色的问题

    <item name="android:colorAccent" tools:targetApi="21">@color/arrows</item>
    <item name="colorAccent">@color/arrows</item>
@颜色/箭头
@颜色/箭头
并对PreferenceActivity布局文件(在我的例子中是settings.xml)中的复选框使用自定义xml

settings.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefSendReport"
        android:summary="@string/desc_daily_not"
        android:title="@string/title_daily_not"
        android:layout="@layout/checkbox_preference"
        android:widgetLayout="@layout/custom_checkbox"
        >
    </CheckBoxPreference>

    <Preference
        android:key="prefSyncFrequency"
        android:summary="@string/pref_sync_frequency_summary"
        android:title="@string/pref_sync_frequency"
        android:layout="@layout/checkbox_preference"
        />

checkbox\u preference.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 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/textAppearanceMedium"
            android:ellipsize="marquee" 
            android:fadingEdge="horizontal"
            android:textColor="@color/arrows"
        />

        <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"
            android:textColor="@color/mdtp_light_gray"
        />

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

自定义复选框.xml

<?xml version="1.0" encoding="UTF-8"?>
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+android:id/checkbox" android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="false"
    android:clickable="false"
/>

在设置活动中创建主题,将以下参数添加到样式中:

 <style name="AppTheme.NoActionBar.SettingActivity"  parent="AppTheme.NoActionBar"> 
         <!--when the check box is checked --!>       
        <item name="colorControlNormal">@color/your-color</item> 
        <!--when the check box is unchecked --!>       
        <item name="colorControlActivated">@color/your-color</item>
  </style>`