2016-06-24 3 views
0

cardView 및 기본 설정으로 설정 메뉴를 만들려고하는데이 두 가지를 결합하는 방법을 잘 모르겠습니다 ... 스크린 샷이 있는데 ListPreference 및 PreferenceScreen 항목을 위의 카드보기 설정. 다음은 레이아웃/setting_group가 PreferenceScreen 당신이 열고 내부를 지적 그를 닫는, 컨테이너입니다기본 설정과 CardView 결합 방법

<PreferenceScreen 
    android:layout="@layout/setting_title_top" 
    android:title = "Padding" /> 
<PreferenceScreen 
    android:layout="@layout/setting_group"> 
</PreferenceScreen> 
<ListPreference 
    android:id="@+id/list" 
    android:layout="@layout/setting_menu" 
    android:dialogTitle = "title one" 
    android:key = "key_1" 
    android:title = "ListPreference" 
    android:summary = "Summary" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
</ListPreference> 

<PreferenceScreen 
    android:layout="@layout/setting_menu" 
    android:key="Key two" 
    android:summary="Summary" 
    android:title="PreferenceScreen" /> 
<PreferenceScreen 
    android:layout="@layout/setting_title" 
    android:title = "Another Setting" /> 

enter image description here

답변

1

cardview에게 인 preference.xml입니다.

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 




    <EditTextPreference 
    android:capitalize="words" 
    android:defaultValue="@string/default_value" <!--The initial state of the preference --> 
    android:key="@string/pref_key" <!-- The key for retrieve the preference --> 
    android:singleLine="true" 
    android:title="@string/pref_title" /> <!-- The title who is showing above the preference --> 


</PreferenceScreen> 

편집 :

당신은 그런 환경을 만들 수 있습니다 환경 설정의 레이아웃에 XML 파일을 생성하고 생성 및 활동, 예 :

public class SettingsActivity extends PreferenceActivity 
    implements Preference.OnPreferenceChangeListener { 
@Override 
public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    addPreferencesFromResource(R.xml.pref_general); 
    bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_key))); // Is deprecated, but still a good option to no need change the values manually. 


} 

private void bindPreferenceSummaryToValue(Preference preference) { 
    preference.setOnPreferenceChangeListener(this); 

    onPreferenceChange(preference, PreferenceManager 
      .getDefaultSharedPreferences(preference.getContext()) 
      .getString(preference.getKey(), "")); 

} 


@Override 
public boolean onPreferenceChange(Preference preference, Object value) { 
    String stringValue = value.toString(); 
    preference.setSummary(stringValue); 



    return true; 
} 
} 
+0

안녕 루카스, 나는에 노력 내 ListPreference 코드를 preferenceScreen에 "@ layout/setting_group"으로 붙여 넣으면 아무 것도 나타나지 않습니다. 기본 설정을 카드보기에 어떻게 삽입합니까? – Deidara

+0

왜 카드보기가 필요한가요? 환경 설정 화면은 Google 머티리얼 디자인 가이드 라인을 사용하고 PreferenceScreen을 만들고 필요한 필드를 다른 컨테이너가 필요 없도록 만듭니다. –

+0

나는 안드로이드의 원래 메뉴처럼 보이는 설정 메뉴를 만들고 싶습니다. UI가 더보기 좋게 보이도록 구성 요소를 사용자 정의해야합니다. – Deidara

관련 문제