如何使用Android复选框创建设置菜单

如何使用Android复选框创建设置菜单,android,android-preferences,preferenceactivity,android-checkbox,preferencescreen,Android,Android Preferences,Preferenceactivity,Android Checkbox,Preferencescreen,我想创建一个首选项屏幕,其中有三个复选框;第一个按钮是可点击的,其他两个按钮只有在选中第一个按钮后才会被点击 我该怎么做?我看到了,但只有一个复选框。有人能帮我吗?你必须像那个例子那样做,但是你会有三个复选框,而不是一个。如果要禁用两个复选框,直到第一个复选框为true,则可以使用android:dependency属性。使用此属性,您需要指定它们所依赖的首选项的键 <PreferenceCategory android:summary="..." android:titl

我想创建一个首选项屏幕,其中有三个复选框;第一个按钮是可点击的,其他两个按钮只有在选中第一个按钮后才会被点击


我该怎么做?我看到了,但只有一个复选框。有人能帮我吗?

你必须像那个例子那样做,但是你会有三个
复选框,而不是一个。如果要禁用两个
复选框,直到第一个复选框为true,则可以使用
android:dependency
属性。使用此属性,您需要指定它们所依赖的首选项的

<PreferenceCategory
    android:summary="..."
    android:title="..." >

    <CheckBoxPreference
        android:defaultValue="true"
        android:key="first"
        android:summary="@string/summary_first"
        android:title="@string/title_first" />

    <CheckBoxPreference
        android:defaultValue="false"
        android:dependency="first"
        android:key="second"
        android:summary="@string/summary_second"
        android:title="@string/title_second" />

    <CheckBoxPreference
        android:defaultValue="false"
        android:dependency="first"
        android:key="third"
        android:summary="@string/summary_third"
        android:title="@string/title_third" />
</PreferenceCategory>

您还可以使用更推荐的片段来执行此操作。但上述方法要简单得多。如果您想对片段执行此操作,请检查其中包含创建设置活动所需的所有信息

希望这有帮助。


哇,这太棒了!非常感谢。我必须在java中设置一些东西吗?
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
     <PreferenceCategory
           android:summary="@string/summary_category"
           android:title="@string/title_category">
           <CheckBoxPreference
                 android:key="main"
                 android:defaultValue="true"
                 android:summary="@string/summary_main"
                 android:title="@string/title_main" 
          />
          <CheckBoxPreference
                android:key="firstDependent"
                android:summary="@string/summary_firstDependent"
                android:title="@string/title_firstDependent"
                android:dependancy="main"
          />
          <CheckBoxPreference
                android:key="secondDependent"
                android:summary="@string/summary_secondDependent"
                android:title="@string/title_secondDependent"
                android:dependancy="main"
          />
    </PreferenceCategory>
<!--Any other categories include here-->
</PreferenceScreen>
public class SettingsActivity extends PreferenceActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);


    }


}