我已經做了一個應用程序,使用一個導航抽屜打開一些不同的片段。我有操作欄drawertoggle,但它不是很明顯。 如果我在我的主要片段(當我的應用第一次啓動時出現的片段)中的onCreateView中放置一個按鈕,我怎樣才能打開由我的活動控制的導航抽屜?如何打開導航抽屜上的按鈕點擊主要片段?
這似乎工作。答案比我想象的要簡單得多。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View fragView = inflater.inflate(R.layout.mainmenu, container, false);
button1 = (Button) fragView.findViewById(R.id.button1);
mDrawerLayout = (DrawerLayout)getActivity().findViewById(R.id.drawer_layout);
mDrawerList = (ListView)getActivity().findViewById(R.id.left_drawer);
button1.setOnClickListener(this);
return fragView;
}
@Override
public void onClick(View v) {
mDrawerLayout.openDrawer(mDrawerList);
}
謝謝你的回答。
你是否得到了答案 – DKV