显示在图像按钮点击溢出菜单 [英] Show overflow menu on Image button click

查看:166
本文介绍了显示在图像按钮点击溢出菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示在溢出菜单的ImageButton 点击

I want to show the Overflow menu on ImageButton click.

菜单/ menu_scrollable_tab.xml

menu/menu_scrollable_tab.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    tools:context="com.example.scrollingtab.activity.ScrollableTabsActivity">

    <item android:id="@+id/action_settings" 
        android:title="@string/action_settings"
        android:orderInCategory="100" 
        app:showAsAction="always"
        android:icon="@drawable/info" />

      <item android:id="@+id/action_settings1" 
        android:title="@string/action_settings"
        android:orderInCategory="100" 
        app:showAsAction="never" />

        <item android:id="@+id/action_settings2" 
        android:title="@string/action_settings"
        android:orderInCategory="100" 
        app:showAsAction="never" />
</menu>

我已经禁用了默认的操作栏,并使用布局创建行动吧。我不使用默认的操作栏或工具栏,因为我需要自定义动作条以上。

I have disabled the default Action bar and created Action bar using layout. I am not using default action bar or toolbar since i need to customize the action bar more.

布局/ actionbar.xml

layout/actionbar.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="50dp" >
 <LinearLayout      
     android:layout_width="fill_parent"
     android:layout_height="50dp"
     android:orientation="horizontal"
     android:background="@color/actionbar_bg"
     android:weightSum="2">

     <ImageButton android:id="@+id/ib_navigation"
         android:background="@drawable/nv_drawer_24x24"
         android:layout_width="0dp"
         android:layout_weight=".3"
         android:layout_height="50dp"/>

     <View 
         android:layout_width="0dp"
         android:layout_height="50dp"
         android:layout_weight="1.1"/>

     <ImageButton android:id="@+id/ib_navigation1"
         android:background="@drawable/info"
         android:layout_width="0dp"
         android:layout_weight=".3"
         android:layout_height="50dp"/>

     <ImageButton android:id="@+id/ib_navigation2"
         android:background="@drawable/ic_drawer"
         android:layout_width="0dp"
         android:layout_weight=".3"
         android:layout_height="50dp"/>     
 </LinearLayout>
</RelativeLayout>

根据客户要求我设计使用的布局和外观的操作栏都不错。

As per the client requirement I have designed the action bar using layout and the look and feel are good.

默认 OnCreateOptionsMenu(菜单菜单)方法不填充溢出菜单。现在我想以填充点击的ImageButton ID = ib_navigation2 溢出菜单。我没有任何想法来实现这一点。

The default OnCreateOptionsMenu(Menu menu) method is not populating the overflow menu. Now i want to populate the overflow menu on clicking the ImageButton with id= ib_navigation2. I don't have any idea to implement this.

任何一个可以帮助我在这样做。

Can any one help me on doing this.

感谢

推荐答案

您需要覆盖的方法,用于创建您自己的菜单

You need to override the method for creating you own menu

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

该buttonclick可以调用 openOptionsMenu();

button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        openOptionsMenu();
    }
});

否则

public myOnClickMethod(View v) {
    openOptionsMenu();
}

在这里看到关于菜单的详细信息
http://developer.android.com/guide/topics/ui/menus.html

希望这会为你工作。

这篇关于显示在图像按钮点击溢出菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆