0

SettingsActivity을 android 환경 설정으로 만들었습니다.PreferenceFragment 버튼 (환경 설정)이 활성화되어 있지 않지만 CheckBoxPreference 작업

SettingsActivity에서 나는 SherlockFragmentActivity을 확장하므로 PreferenceFragment을 사용하기로 결정했습니다.

PreferenceFragment이라는 확장 클래스 (GenericPreferenceFragment)가 리소스에서 환경 설정 xml을로드하는 맞춤 클래스를 만들었습니다.

기본 설정은 버튼 2 개와 확인란 2 개입니다.

내 안드로이드 업데이트로 넥서스에서 모두 잘 작동하지만, 안드로이드 4.2를 사용하는 삼성에서는 버튼이 활성화되어 있지 않습니다. (회색)! 여기

화면 :

android < 4.4 buttons not enabled

그 이유는 무엇입니까? 이 문제를 어떻게 해결할 수 있습니까?


코드 : 여기

com.xxx.yyy.SettingsActivity의 일부는 다음과 같습니다

public class SettingsActivity extends SherlockFragmentActivity implements 
     OnPreferenceClickListener, OnClickListener { 

    private final String TAG = "SETTINGS"; 
    private ImageButton homeButton; 
    private ImageButton settingsButton; 
    private TextView activityTitle; 

    private ProgressDialog pDialog; 
    private GenericPreferenceFragment gPrefFragment; 

    private CheckBoxPreference cbpGCM; 
    private CheckBoxPreference cbpMail; 
    private Preference pKeywords; 
    private Preference pLogout; 



    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     return super.onOptionsItemSelected(item); 
    } 


    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_settings); 

     setupActionBar(); 
     gPrefFragment = (GenericPreferenceFragment) getFragmentManager().findFragmentById(R.id.pref_frag_id); 

     FontsOverride.setDefaultFont(getApplicationContext(), "DEFAULT", 
       "OpenSans-Regular.ttf"); 
     layoutInitializer(); 
    } 

    // @Override 
    // public void onBuildHeaders(List<Header> target) { 
    // loadHeadersFromResource(R.xml.preference_headers, target); 
    // } 

    private void setupActionBar() { 
     getSupportActionBar(); 
     getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
     getSupportActionBar().setCustomView(R.layout.custom_abs_layout); 
    } 

    private void layoutInitializer() { 
     pDialog = DialogUtil.makeDialog(SettingsActivity.this); 

     // --- ACTIONBAR --- 
     homeButton = (ImageButton) findViewById(R.id.button_menu_home); 
     settingsButton = (ImageButton) findViewById(R.id.button_menu_settings); 
     activityTitle = (TextView) findViewById(R.id.tv_activity_title); 
     activityTitle.setText(R.string.title_settings); 

     homeButton.setBackgroundResource(0); 
     settingsButton.setBackgroundResource(0); 
     homeButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_return)); 


     cbpGCM = (CheckBoxPreference) gPrefFragment.findPreference("pref_device_notification"); 
     cbpMail = (CheckBoxPreference) gPrefFragment.findPreference("pref_mail_notification"); 
     pKeywords = (Preference) gPrefFragment.findPreference("pref_keyword"); 
     pLogout = (Preference) gPrefFragment.findPreference("pref_logout"); 

     pKeywords.setOnPreferenceClickListener(this); 
     pLogout.setOnPreferenceClickListener(this); 
     cbpMail.setOnPreferenceClickListener(this); 
     cbpGCM.setOnPreferenceClickListener(this); 

     homeButton.setOnClickListener(this); 


     // set button on/off 
      ... 
     cbpGCM.setChecked(gcmStatus); 
     cbpMail.setChecked(mailStatus); 
    } 

    @Override 
    public boolean onPreferenceClick(Preference preference) { 
     String key = preference.getKey(); 
     if (key.equalsIgnoreCase("pref_keyword")) { 
      finish(); 
      startActivity(...); 
     } else if (key.equalsIgnoreCase("pref_logout")) { 
      getLogout(); 
     }else if (key.equalsIgnoreCase("pref_device_notification")) { 
      boolean status = cbpGCM.isChecked(); 
      switchGCM(status); 
     } else if (key.equalsIgnoreCase("pref_mail_notification")) { 
      boolean status = cbpMail.isChecked(); 
      switchMail(status); 
     } 

     return false; 
    } 
} 

이 R.layout.activity_settings입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_margin="10dp" 
     android:background="#" 
     android:orientation="vertical" > 

     <fragment 
      android:id="@+id/pref_frag_id" 
      android:name="com.xxx.yyy.GenericPreferenceFragment" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 
    </LinearLayout> 

</LinearLayout> 

이 내 com.xxx.yyy.GenericPreferenceFragment입니다 :

public class GenericPreferenceFragment extends PreferenceFragment { 

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

    } 
} 

그리고 이것은 R.xml.preferences에게입니다 :

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#" > 

    <PreferenceCategory 
     android:key="pref_keyword_settings" 
     android:title="@string/label_keyword_settings" > 
     <Preference 
      android:dependency="pref_keyword_settings" 
      android:icon="@drawable/ic_keyword_settings" 
      android:key="pref_keyword" 
      android:summary="@string/description_keyword_preference" 
      android:title="@string/title_keyword_preference" /> 
    </PreferenceCategory> 


    <PreferenceCategory 
     android:key="pref_notification_settings" 
     android:title="@string/label_notification_settings" > 
     <CheckBoxPreference 
      android:defaultValue="true" 
      android:icon="@drawable/ic_notification_settings" 
      android:key="pref_device_notification" 
      android:summary="@string/description_device_notification" 
      android:title="@string/title_device_notification" /> 
     <CheckBoxPreference 
      android:defaultValue="true" 
      android:icon="@drawable/ic_mail_settings" 
      android:key="pref_mail_notification" 
      android:summary="@string/description_mail_notification" 
      android:title="@string/title_mail_notification" /> 
    </PreferenceCategory> 


    <PreferenceCategory 
     android:key="pref_logout_settings" 
     android:title="@string/label_logout_settings" > 
     <Preference 
      android:dependency="pref_logout_settings" 
      android:icon="@drawable/ic_logout" 
      android:key="pref_logout" 
      android:enabled="true" 
      android:summary="@string/description_logout_preference" 
      android:title="@string/title_logout_preference" /> 
    </PreferenceCategory> 

</PreferenceScreen> 

답변

0

내가 솔루션을 가지고 몇 가지 시도한다 후 : android:dependency = "pref_keyword_settings"android:dependency = "pref_logout_settings"R.xml.preferences에서 삭제해야합니다. 종속성이있는 Preferences.isEnable() 결과는 항상 false입니다!