我正在編寫一個Android應用程序以利用抽屜佈局功能。我希望能夠將Drawer Layout作爲整個應用程序中可用的導航工具。要使用抽屜佈局,我用我的活動佈局的XML文件如下:如何在Android應用程序中圍繞PreferenceActivity包裝DrawerLayout?
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<LinearLayout
android:id="@+id/main_content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/navigational_drawer"
android:layout_width="220dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#FFFFFF"/>
</android.support.v4.widget.DrawerLayout>
不過,我有一個很大的包裹DrawerLayout圍繞PreferenceActivity困難。 PreferenceActivity是一種特殊的活動,我想保留它,因爲它可以幫助我在應用中保持Android偏好的外觀和風格;就是說,它使用addPreferencesFromResource()調用來加載首選項,並且不使用addContentView()調用來加載XML文件;首選項資源通常包含不喜歡包裝在DrawerLayouts中的PreferenceScreen標籤。
任何人都必須處理這個問題,你是如何解決它的?如果您在Android應用中擁有PreferenceActivity,並且您的DrawerLayout可用於同一活動,請分享您是如何做到的。任何幫助將非常感激。
編輯:如果我改變
<!-- The main content view -->
<LinearLayout
android:id="@+id/main_content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
到
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
那麼當PreferenceActivity被加載(因爲ID「列表」匹配什麼偏好活動期待的應用程序不會崩潰找);然而,抽屜沒有顯示。這幾乎就好像ListView「list」下面的所有內容都被忽略了一樣。
我也想保留我現有的活動並動態添加抽屜。不是因爲PreferenceActivity,而是因爲有將近100個活動並將它們全部更改爲碎片需要一段時間。我能夠用HorizontalScrollView來做到這一點,但我覺得DrawerLayout會更乾淨。 –