2016-08-31 4 views
0

내 설정 메뉴에 대한 PreferenceScreen (pref_screen.xml)을 만들었습니다. 여기에는 다른 범주의 개체 목록이 포함되어 있습니다. 단추,보기, 텍스트, 이미지를 포함하는 또 다른 사용자 지정 레이아웃 (settings.xml)을 만들었습니다.android에서 사용자 정의 환경 설정 화면 만들기

내 PreferenceScreen에 내 사용자 정의 레이아웃의 내용을 표시하는 방법을 알고 싶습니다.

내 pref_screen.xml

<?xml version="1.0" encoding="utf-8"?> 
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 


    <PreferenceCategory 
     android:title="Flight Selection" > 

     <Preference 
      android:title="Change Flight" 
      android:selectable="true" 
      android:key="@string/choose_flight" 
      android:icon="@drawable/icon_select_flight" /> 
     <Preference 
      android:title="Close Flight" 
      android:selectable="true" 
      android:key="@string/close_flight_successful" 
      android:icon="@drawable/icon_select_flight" /> 

    </PreferenceCategory> 

    <PreferenceCategory 
     android:title="Terminal Panel" > 

     <Preference 
      android:title="Change Terminal" 
      android:selectable="true" 
      android:icon="@drawable/icon_terminal" /> 

    </PreferenceCategory> 

    <PreferenceCategory 
     android:title="Printer Panel" > 

     <Preference 
      android:title="Choose Printer" 
      android:icon="@drawable/icon_printer" /> 

    </PreferenceCategory> 

    <PreferenceCategory 
     android:title="AirFi Sync" > 

     <SwitchPreference 
      android:title="Enable Sync" /> 

     <Preference 
      android:title="Sync Group" 
      android:icon="@drawable/airfi" /> 

     <Preference 
      android:title="Sync Details" 
      android:icon="@drawable/airfi" /> 

    </PreferenceCategory> 


</PreferenceScreen> 

입니다 그리고 이것은 개인 preferenceScreenusing에 대한

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/settings_content" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:layout_marginLeft="5dp" 
    android:layout_marginRight="5dp" 
    android:orientation="vertical" 
    android:weightSum="10" > 



     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="35dp" 
      android:id="@+id/relativeLayout3"> 

     </RelativeLayout> 
     <View 
      android:layout_width="match_parent" 
      android:layout_height="2dp" 
      android:background="@color/transparent" 
      android:layout_below="@+id/relativeLayout2" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:id="@+id/view" /> 

     <Button 
      android:layout_margin="10dp" 
      android:id="@+id/select_flight_button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentStart="true" /> 


     <Button 
      android:layout_margin="10dp" 
      android:id="@+id/close_leg" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

     <Button 
      android:layout_margin="10dp" 
      android:visibility="visible" 
      android:id="@+id/configure_printer" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/white_button_bg_state_list" 
      android:drawableLeft="@drawable/icon_printer" 
      android:maxHeight="@dimen/global_button_height" 
      android:minHeight="@dimen/global_button_height" 
      android:text="@string/choose_printer" 
      android:textColor="@drawable/custom_text_color_for_buttons" 
      android:textSize="@dimen/button_text_size" 
      android:textStyle="bold" 
      android:layout_below="@+id/textView4" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

     <Button 
      android:layout_margin="10dp" 
      android:visibility="visible" 
      android:id="@+id/configure_print_format" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@id/configure_printer" 
      android:layout_gravity="center" 
      android:layout_marginTop="10dp" 
      android:background="@drawable/white_button_bg_state_list" 
      android:drawableLeft="@drawable/icon_printer" 
      android:maxHeight="@dimen/global_button_height" 
      android:minHeight="@dimen/global_button_height" 
      android:text="@string/change_printer_format" 
      android:textColor="@drawable/custom_text_color_for_buttons" 
      android:textSize="@dimen/button_text_size" 
      android:textStyle="bold" /> 

     <Button 
      android:layout_margin="10dp" 
      android:visibility="visible" 
      android:id="@+id/configure_payment_device" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/white_button_bg_state_list" 
      android:drawableLeft="@drawable/icon_terminal" 
      android:maxHeight="@dimen/global_button_height" 
      android:minHeight="@dimen/global_button_height" 
      android:text="@string/change_payment_device" 
      android:textColor="@drawable/custom_text_color_for_buttons" 
      android:textSize="@dimen/button_text_size" 
      android:textStyle="bold" 
      android:layout_below="@+id/textView3" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

     <TextView 
      android:textStyle="bold" 
      android:textSize="20sp" 
      android:text="Terminal Panel" 
      android:textColor="@color/adyen_green" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/close_leg" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:id="@+id/textView3" /> 

     <TextView 
      android:textStyle="bold" 
      android:textSize="20sp" 
      android:text="Printing Panel" 
      android:textColor="@color/adyen_green" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/configure_payment_device" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:id="@+id/textView4" /> 


    </RelativeLayout> 


    <View 
     android:id="@+id/divider_net_sales" 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="5dp" 
     android:background="@color/transparent" /> 




    <RelativeLayout 
     android:id="@+id/ifs_panel" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:visibility="visible" 
     android:gravity="bottom"> 

     <View 
      android:id="@+id/divider_ifs_panel" 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:visibility="gone" 
      android:background="@color/transparent" /> 

     <TextView 
      android:id="@+id/sync" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_below="@id/divider_ifs_panel" 
      android:layout_centerHorizontal="true" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp" 
      android:text="@string/airfi_sync" 
      android:textSize="18sp" 
      android:visibility="gone" 
      android:textStyle="bold" /> 

    </RelativeLayout> 

</LinearLayout> 
+0

'Preference' (또는'Preference'의 서브 클래스)를 확장하는 클래스를 생성하고'org.test.MyPreference'와 같이'org.test.MyPreference ... />'대신'< Preference ... />' – pskink

+0

settings.xml은 SettingsFragment 클래스에 의해 처리됩니다. PreferenceActivity 클래스에서이 조각을 어떻게 사용할 수 있습니까? – telmomarques

+0

코드 스 니펫 pskink를 추가 할 수 있습니까? – telmomarques

답변

0

세트 레이아웃이 내 Settings.XML이있다 :이 사용 findViewById

<Preference 
    android:title="@string/label_pref_version" 
    android:key="@string/pref_version" 
    android:layout="@layout/pref" /> 

에 customlayout의 요소에 액세스합니다.

+0

내 PreferenceActivity 클래스에서 findViewById를 사용합니까? 죄송합니다. Android를 처음 사용합니다. – telmomarques

+0

활동 코드에 예. –

관련 문제