开发者

how to display button when menu button is pressed in android

开发者 https://www.devze.com 2023-01-20 21:07 出处:网络
h开发者_运维问答i friends i want to pop up a button from the bottom of my screen when the default menu button is pressed on the android key pad. i want to navigate from that pop button to other screen

h开发者_运维问答i friends i want to pop up a button from the bottom of my screen when the default menu button is pressed on the android key pad. i want to navigate from that pop button to other screens.


You first have to declare your desired menu in /menu/menu.xml then you need a inflater for your menu:

// menuinflater 
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}

And to handle your menu:

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        // only one menu option here for preferences
        // for more just add new case with your ids
        case R.id.firstmenuitem:
            // Launch preferences activity
            Intent i = new Intent(youractivity.this, preferences.class);
            startActivity(i);
            break;

        }
        return true;
    }       

regards

0

精彩评论

暂无评论...
验证码 换一张
取 消