Android Navigation: Menus, ActionBar/ToolBar, and Navigation Drawer Ro’zimurodov Nodirjon



Download 0,86 Mb.
bet2/7
Sana13.12.2022
Hajmi0,86 Mb.
#885109
1   2   3   4   5   6   7

Item1

item2

Sub menus in xml

  • Create and item that will be the submenu heading
    • Then create a menu instead of the item tags.

...

...

...

Menu Java code

  • Use onCreateOpensMenu and onOptionsItemSelected
      • Which android studio creates for you by default
      • @Override

        public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.

        getMenuInflater().inflate(R.menu.menu, menu);

        return true;

        }

        @Override

        public boolean onOptionsItemSelected(MenuItem item) {

        // Handle action bar item clicks here.

        int id = item.getItemId();

        if (id == R.id. item1) { //assuming previous xml document

        return true; //do something here to handle the menu.

        } … //handle the rest.

        return super.onOptionsItemSelected(item);

        }

Popup menus.

  • Add a click listener (or longtouch, whatever) to anything.

showPopupMenu

private void showPopupMenu(View v){

PopupMenu popupM = new PopupMenu(this, v);

popupM.inflate(R.menu.popup);

popupM.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

@Override

public boolean onMenuItemClick(MenuItem item) {

//do something

return true;

}

});

popupM.show();

}

Popup Menus Visual

Fragments and Menus

  • Fragments can contribute to the menu as well
    • Including if there is no menu.
    • In the OnCreate() method of the fragment, you must add
      • setHasOptionsMenu(true);
        • Otherwise the menu methods will not be called.
  • A note, when the fragment is showing, the menu will be there and when the fragment is “removed”, then those menu items are removed as well.

Download 0,86 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish