仿ActionBar overflow溢出,竖线菜单效果

XML布局:

        <ImageButton
            android:id="@+id/ib_menu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:background="@drawable/selector_imgbtn_menu" />

菜单XML:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/menu_login"
        android:title="Login"/>
    <item
        android:id="@+id/menu_save"
        android:title="Save"/>
    <!-- menu group -->
    <group android:id="@+id/menu_group" >
        <item
            android:id="@+id/menu_edit"
            android:title="Edit"/>
        <item
            android:id="@+id/menu_delete"
            android:title="Delete"/>
    </group>

</menu>


MainActivity:
                more = (ImageButton) findViewById(R.id.more);
		more.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				final PopupMenu popupMenu = new PopupMenu(MainActivity.this, v);
				MenuInflater menuInflater = new MenuInflater(MainActivity.this);
				menuInflater.inflate(R.menu.main, popupMenu.getMenu());
				popupMenu.show();
				popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
					@Override
					public boolean onMenuItemClick(MenuItem item) {
						Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
						popupMenu.dismiss();
						return false;
					}
				});
			}
		});



你可能感兴趣的:(仿ActionBar overflow溢出,竖线菜单效果)