在我main.xml中佈局,我有一個<FrameLayout>
元素,這就是片段佔位符:獲取片段的視圖,並禁用整個視圖
的main.xml:
<FrameLayout
android:id="@+id/fragment_placeholder"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
我添加片段編程上述<FrameLayout>
由:
fragmentTransaction.add(R.id.fragment_placeholder, fragment, null);
我可以再使用replace()
切換到其他片段:
fragmentTransaction.replace(R.id.fragment_placeholder, otherFragment, null);
在我的項目的一些問題,我需要獲得當前顯示片段,並禁用一切的看法。首先,我順利拿到由當前顯示片段:
Fragment currentFragment = fragmentManager.findFragmentById(R.id.fragment_placeholder);
然後,我怎麼能禁用片段的看法?在視圖中,可能有按鈕,是否可以禁用整個視圖?如果不可能,我該如何在視圖上添加疊加層?
我想:
currentFragment.getView().setEnabled(false);
但是,它不工作,我仍然可以點擊按鈕,在視圖。
這裏檢查http://stackoverflow.com/questions/5418510/disable-the-touch-events-for-all-the-views和這裏http://stackoverflow.com/questions/7068873/how-can- i-disable-all-views-inside-the-layout – 2012-08-02 10:51:56