2012-01-19 15 views
10

मैं एक वरीयता स्क्रीन बनाने की कोशिश कर रहा हूं लेकिन मैं पूरी परियोजनाओं की तरह गतिविधि डिजाइन चाहता हूं।एंड्रॉइड: कस्टम वरीयता स्क्रीन कैसे बना सकता है?

कस्टम वरीयता स्क्रीन डिज़ाइन कैसे बना सकता है?

+0

क्षमा करें, क्या आप अपना प्रश्न बढ़ा सकते हैं? या शायद इसे और अधिक साफ कर सकते हैं? मुझे लगता है कि तुम्हारा एक डिजाइन/ग्राफ़िक समस्या – StErMi

+0

है, लेकिन मैं इसके काम करने के लिए पूछना चाहता हूं। – Basbous

उत्तर

2

मुझे लगता है कि यह वही है जो आप खोज रहे हैं।

PreferenceScreen screen = createPreferenceHierarchy(); 

..
this.setContentView(rootView); => मैं आप भी XML लेआउट से सेट कर सकते हैं लगता है।

setPreferenceScreen(screen); 
+0

लिंक टूटा हुआ है :( – philipp

12

हाँ, यह करने योग्य है। लेआउट के लिए क्षमा याचना, मेरी चिपकाने कभी नहीं

import android.content.Intent; 
    import android.os.Bundle; 
    import android.preference.PreferenceActivity; 
    import android.view.View; 
    import android.widget.Button; 

    public class Preferences extends PreferenceActivity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.preference_holder); 
    addPreferencesFromResource(R.layout.preferences); 

    Button backButton = (Button) findViewById(R.id.backPrefBurron); 
    backButton.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View view) { 
      Intent myIntent = new Intent(getBaseContext(), 
        BTFirstTab.class); 
      startActivity(myIntent); 
     } 
    }); 

    } 
    } 

तो एक वरीयताओं holder.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:orientation="vertical"> 
<LinearLayout android:orientation="horizontal" 
    android:background="@color/bto_dark_green" android:layout_width="fill_parent" 
    android:gravity="center_vertical" android:layout_height="wrap_content" 
    android:paddingTop="4dip"> 
    <Button android:id="@+id/backPrefBurron" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:text="Home" /> 

    <TextView android:id="@+id/backText" android:textSize="14dip" 
     android:paddingLeft="5dip" android:textColor="@color/white" 
     android:textStyle="bold" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_weight="1.0" 
     android:text="Preferences: Home will update all areas of the app" /> 
</LinearLayout> 
<ListView android:id="@android:id/list" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 
</LinearLayout> 

तो वरीयताओं सही स्वरूपण रखने के लिए लगता है, लेकिन सामग्री काम करता है ...

Preferences.java .xml

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

<EditTextPreference android:title="Your BTO UserName" 
    android:key="username" android:summary="Please provide your username">   </EditTextPreference> 
<EditTextPreference android:title="Your BTO Password" 
    android:password="true" android:key="password" android:summary="Please provide your password (case sensitive)"></EditTextPreference> 
<ListPreference android:title="Species order" 
    android:summary="This preference selects the species order for some viewing sightings activities" 
    android:key="speciesorder" android:defaultValue="date_order" android:entries="@array/listArray" 
    android:entryValues="@array/listValues"></ListPreference> 
    </PreferenceScreen> 

इस तरह मेरे पास एक सामान्य शीर्षलेख है जिसका मैं अन्य पृष्ठों में उपयोग करता हूं।

+0

यह वांछित है जब मैं वरीयता का उपयोग कर रहा हूं? – Michal

संबंधित मुद्दे