2014-02-24 57 views
2

任何人都可以告诉我如何在偏好活动中实现导航抽屉吗?Android NavigationDrawer with PreferenceActivity

我的Java代码。

package com.example.android.navigationdrawerexample; 
import android.os.Bundle; 
import android.preference.PreferenceActivity; 
public class AppPreferences extends PreferenceActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     addPreferencesFromResource(R.xml.as); 
    } 
} 

我的XML代码:

<?xml version="1.0" encoding="utf-8"?> 
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 
    <EditTextPreference android:title="Your Name" 
         android:key="username" 
         android:summary="Please provide your username"></EditTextPreference> 
    <CheckBoxPreference android:title="Application Updates" 
         android:defaultValue="false" 
         android:summary="This option if selected will allow the application to check for latest versions." 
         android:key="applicationUpdates" /> 
    <ListPreference  android:title="Download Details" 
         android:summary="Select the kind of data that you would like to download" 
         android:key="downloadType" 

        /> 
</PreferenceScreen> 

请人指点我。我在等待你的回应。

回答

2

尝试使用带有FragmentActivity而不是PreferenceActivity的PreferenceFragment。

+0

您是否知道任何支持具有PreferenceFragment的导航抽屉的示例? – itsrajesh4uguys

+0

下面是你如何创建一个抽屉:http://developer.android.com/training/implementing-navigation/nav-drawer.html 你插入页面的片段的类是一个完全indeoendent的东西。 – Ripityom

+0

我现在只在活动的支持下使用该示例。现在我正在尝试更改以将导航抽屉添加到已经工作的首选项屏幕中。我可以这样做吗? – itsrajesh4uguys

0

这是不可能同时使用PreferenceActivity和NavigationDrawer由于两个相互排斥的选项:

  1. PreferenceActivity有夸大自己的内部布局。
  2. DrawerLayout必须是元素的布局。

所以,我认为这是路的尽头。