เมนูแถบการดำเนินการในส่วนย่อยไม่ปรากฏขึ้น

ฉันกำลังพยายามสร้าง Action Bar ด้วยตัวเลือกเดียวในส่วนย่อย แต่มันไม่ทำงาน และฉันได้ปฏิบัติตามขั้นตอนทั้งหมดที่ระบุไว้ในบทช่วยสอนทางอินเทอร์เน็ตแล้ว:

  1. สร้างฟังก์ชัน "onCreate" ซึ่งจะไม่ปรากฏตามค่าเริ่มต้น โดยมี "sethasoptionmenu(true)"
  2. เขียนฟังก์ชัน "onCreateOptionsMenu" ด้วย "inflater.inflate(R.menu.menu_fotos, menu);"
  3. สร้างฟังก์ชัน "onOptionsItemSelected"

ด้วยเหตุนี้สิ่งที่ฉันได้รับคือเมนูตัวเลือกปกติ แต่สิ่งที่ฉันต้องการคือเมนู Action Bar! คุณสามารถช่วยฉันได้ไหม?

ฉันคัดลอกโค้ดของส่วนมาที่นี่:

    package com.carlesqf.laguerra;

    import *.*;

    public class FragmentContingutCapitols extends Fragment {   

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setHasOptionsMenu(true);
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View v= inflater.inflate(R.layout.activity_contingutcapitols, null);        
            // Getting the bundle object passed from "PantallaContingutCapitols"  
            Bundle b = getArguments();      
            String nomcap=LlistaCapitols.name[b.getInt("position")];
            if (nomcap.contains("1700-1701 Les causes del conflicte:"))
                v = inflater.inflate(R.layout.capitol1700, null);
            else if ((nomcap.contains("1702 – Primers combats. Itàlia i front del Rin:"))) 
                v = inflater.inflate(R.layout.capitol1702, null);
... 
            return v;
        }   

        @Override
        public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
            // Do something that differs the Activity's menu here
            super.onCreateOptionsMenu(menu, inflater);      
            inflater.inflate(R.menu.menu_fotos, menu);  
        }   

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.action_settings:
               // do s.th.
               return true;
            default:
                return super.onOptionsItemSelected(item);
            }
        }
    }

person Carles Quintana Fernandez    schedule 20.01.2015    source แหล่งที่มา


คำตอบ (1)


จริงๆ แล้วเมนูแถบการทำงานเป็นเมนูตัวเลือกปกติ NavigationDrawer คือสิ่งที่คุณกำลังมองหาใช่ไหม?

person Joan S.    schedule 20.01.2015
comment
สิ่งที่ฉันกำลังมองหาคือระบบที่จะส่งคืนจากแฟรกเมนต์ B ซึ่งผู้ใช้สามารถอ่านเนื้อหาของบทไปยังแฟรกเมนต์ A ซึ่งมีดัชนีของบทที่แตกต่างกัน ฉันสามารถใช้ปุ่มเริ่มต้นของโทรศัพท์ได้ แต่แถบการทำงานจะดีกว่า - person Carles Quintana Fernandez; 20.01.2015